+ Reply to Thread
Results 1 to 18 of 18

Counting spefici text within a range

  1. #1
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Counting spefici text within a range

    I am wanting to count the number of times a specific word appears within a range and then assign that value to a cell. I am not sure of the best way to go about this as the code seems to work but I get errors like "Method 'Value' of object 'Range' failed".

    This is what I have thus far:

    Please Login or Register  to view this content.

    I've then called the function.

    Is it possible to do this without specifying a static range? For example, as long as each row has a value in column A, then count the number of times the word "pending" appears in those rows?

    Thanks for any input

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Counting spefici text within a range

    This will look in Column A for the last record. It will then search column O as required for the range O12 to last record in column O. I hope that is what you meant.

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Counting spefici text within a range

    @alansidman

    If I am not wrong, you probably did not notice the error in the OP's code in the line Range("D4").Value = wordcount as wordcount is not calculated in the code so will have a value equal to 0. I think the little modification is needed.

    Please Login or Register  to view this content.
    Last edited by sktneer; 12-06-2013 at 01:20 PM.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Counting spefici text within a range

    That works to a degree as long as you make some changes.

    Please Login or Register  to view this content.
    It works fine until the number of times the word appears increases or decreases and then it throws this error at me:
    Method 'Value' of object 'Range' failed

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Counting spefici text within a range

    I got no error while I ran this code. Unable to understand your issue. Probably more information is required. Better you upload a sample workbook.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Counting spefici text within a range

    @Cameron213: I ran sktneer's code and it works for me. Make a change and run it again. No issues.

    @sktneer: Thanks. Yeah, I overlooked that completely. Went straight to last line issue.

    Alan

  7. #7
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Counting spefici text within a range

    Not sure exactly the best way to go about uploading a workbook. The contained information is highly confidential. Should be easy, I know. It throws that error and then another one saying "Not enough system resources to display completely"

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Counting spefici text within a range

    Suggest you copy the file, remove sensitive data or dummy up the sensitive data and then post the file. You do not need to post the entire file, but only enough records to make it clear what you have.

    Here is how to post the file.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    BTW:

    Here is my file with sample data that works.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Counting spefici text within a range

    I've created a sample workbook. It contains three columns. Name, Age, and ***. The *** column is a drop down that allows a choice of M or F. The number of Women and Men is then totaled. I am still getting the error. I am assuming it is with the way I am calling the function.

    test.xlsmtest.xlsm

  10. #10
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Counting spefici text within a range

    I've downloaded the book you uploaded. I do not see anything happening when I create a new row and insert the word pending. The number isn't increasing even if I close and re-open it. I've even saved it as macro-enabled.

  11. #11
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Counting spefici text within a range

    Make sure you also insert a value in col. A in the new row because if there is no value in col. A when new row is inserted it will not count the value pending in col. O.

  12. #12
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Counting spefici text within a range

    I did add a value to the A column and then put a value in O. Even if I changed some of the previous values around nothing happened.

  13. #13
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Counting spefici text within a range

    That is so strange! What value you are putting in col. O exactly? Are you still getting an error while running the code? You can upload the workbook which you have downloaded with some new rows added in it. Lets see then what's wrong there.

    Note: After making changes, you have to run the code again as this is not a formula so will not automatically reflect the new value in D4.
    Last edited by sktneer; 12-06-2013 at 02:36 PM.

  14. #14
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Counting spefici text within a range

    test.xlsm

    Maybe I am not understanding correctly or explaining correctly. I did upload a workbook for you to have a look at.

    I download the one you uploaded. I inserted values in Column A and within the same row in Column O inserted Pending or Closed or any word. Once doing so the count never increases or decreases.

    Is the count value supposed to increase on the fly? The only way I found it to work was going to the developer tab, clicking Macros and then running the Test macro.

  15. #15
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Counting spefici text within a range

    The workbook you uploaded had no data in it except headers so useless for us.

    As I mentioned in my last post #13, you need to run the macro again after making any change in the workbook to reflect new value in D4.

  16. #16
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Counting spefici text within a range

    If you want it to change every time you make a change in Column O, then put this VBA in the worksheet event

    Please Login or Register  to view this content.
    Open the VBE
    On the left open the VBA project window if not already open
    Click on the Worksheet that you want this code for.
    In the right window, insert the code.
    Save and close the VBE

  17. #17
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Counting spefici text within a range

    Please find the attached sheet.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    12-05-2013
    Location
    Utah
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Counting spefici text within a range

    Well, having to re-run the macro is pointless for what I am needing. Needs to be able to update on the fly. It doesn't have any data because once you start entering anything it throws that error. If you take a look at the worksheet code you will see the function and the function call within "Worksheet Change"

    I think I may have solved the problem.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Counting the # of Unique Text cells in a range
    By peter_f in forum Excel General
    Replies: 2
    Last Post: 10-16-2010, 06:03 AM
  2. Replies: 2
    Last Post: 05-20-2010, 02:35 AM
  3. Counting text in range subtracting from par
    By desk.doc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-19-2007, 02:29 PM
  4. Counting each time text appears in range???
    By Simon Lloyd in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-09-2006, 08:55 AM
  5. [SOLVED] Counting Occurrence of Text within Text in Cells in Range.
    By Jeremy N. in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-08-2005, 01:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1