+ Reply to Thread
Results 1 to 7 of 7

Counting the number of occurances of a word in a column of variable length

  1. #1
    Registered User
    Join Date
    10-02-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    10

    Counting the number of occurances of a word in a column of variable length

    Hello Y'all,
    I have a spreadsheet with adverse event data. Column A has the adverse event term exactly as the staff member entered it into the database. I am working on creating a report that counts the number of instances that an AE term appears in column A. The issues that I am having trouble with are that there are MANY AE terms, the AE terms are variable (and unpredictable), and the number of rows in the spreadsheet is variable.
    I have figured that the easiest, most organized thing to do is to create a new sheet as the destination for the number of occurances. Below is my code with the trouble area in red:

    Please Login or Register  to view this content.
    I got some numbers and the macro ran with no error messages. However, I can't tell if the numbers ouput by this macro are correctly counting the number of times a word appears in column A. I have attached a mock up of what the final report needs to look like .

    Any and all help is very much appreciated! Thanks, y'all!
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Counting the number of occurances of a word in a column of variable length

    There's no sample data in that workbook for us to compare those results to to see if they are correct.

    Can't you just count values in column A using wildcards and a COUNTIF() formula?

    If column A has text strings.
    If M2 had the word "headache" in it as a string you wanted to count, this formula in N2 would count them for you:

    =COUNTIF(A:A, "*"&M2&"*")
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-02-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Counting the number of occurances of a word in a column of variable length

    I have attached a sample copy of the source data sheet
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Counting the number of occurances of a word in a column of variable length

    So, now you've uploaded two workbooks. How did you decide to pull those two lines out of the sample data? A simpler data set and results along with an explanation of how you decided those were the results could lead to a simple macro to follow that same logic.

  5. #5
    Registered User
    Join Date
    10-02-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Counting the number of occurances of a word in a column of variable length

    The sponsor of the study sent those specs. The logic is kind of backwards from that point. The report they want can't be changed. But I have, in my macro for the results to be put in a new worksheet. So I download the raw data from the database, and then run my macro (that's unfinished). My logic is for every cell in column A, LRow, count the number of times the value of Column A, LRow appears in Column A then post that count in the destination cell in worksheet 2. So for example, say the word headache appears in worksheet 1, Column A a total of 7 times, then the destination cell in worksheet 2 (the first blank cell in column E) will show the value of 7.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Counting the number of occurances of a word in a column of variable length

    With the report sheet open and the data sheet open, put this formula in E3, then copy down, it will search the data sheet column A for the value in column A of the report sheet on that row and give you a count.

    =COUNTIF([AE_Count_Sample_Data.xls]sheet1!$A:$A, "*"&A3&"*")


    Headache appears to = 0, but if you change that to fatigue for example you'd get a count of 6. So whatever terms you're searching for... put them in column A, then that formula will do the rest.

  7. #7
    Registered User
    Join Date
    10-02-2013
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Counting the number of occurances of a word in a column of variable length

    Thank you for your suggestion, but I get the sense you haven't looked at all of the macro code and that you have missed some key parts of my issue.
    The sample data I posted is just that, sample data. The raw data has about 1500 rows and will grow/change as the study is ongoing. Also, I account for empty ceells in my macro by deleting them. Last, this report has to be accessible more than one time and by more than just me.

+ 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. Replies: 4
    Last Post: 04-23-2013, 05:34 AM
  2. counting unique values in a variable length column
    By saimike in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-16-2012, 10:58 AM
  3. Replies: 6
    Last Post: 04-14-2012, 04:07 AM
  4. Counting number of occurances in one coloumn to another column
    By hopkinsii in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-20-2011, 05:41 PM
  5. Counting the number of occurances in a single row
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-08-2010, 03:05 AM

Tags for this Thread

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