+ Reply to Thread
Results 1 to 4 of 4

Count instances of a string across multiple columns with multiple criteria

  1. #1
    Registered User
    Join Date
    12-20-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Count instances of a string across multiple columns with multiple criteria

    Hi all -

    This is a continuation of a prior 'solved' problem (thank you Haseeb A!). I've now been asked to provide a further data parse and I think I'm going to have to use VB to get it - and those skills of mine are old!

    The data is proprietary, so I can't share it. I'm going to attach a fake dummied up version. Essentially, here's the skinny:

    Column A has the name of a person. Columns B thru D have string data with a keyword buried in it, such as Steel Support Beam ("support" is the keyword), Driver Clamp ("clamp" is the keyword). This string data may recur in a row, but I only need to count the occurrence of the string once. I have a formula that performs the count already, thanks to a previous posting on this forum. The new wrinkle: In addition to the count of the individual strings, I now need to know the count of occurrences of each keyword per person.

    In essense:
    Joe: Support = 2
    Clamp = 3

    The dummy sheet I've attached tries to show this, and show the data I'm after. I'm happy to do a script but, as I say, those skills are old - so I could use some help!

    Happy to provide further explanation if needed. Thanks much!
    Rachel

    EDIT: I'm quite comfortable with Pivot tables, but I've yet to see a way to search for a string via Pivot table. If the resulting output from a vb script does nothing more than give a listing of the person's name, and then a listing of the keyword next to it, that's fine. I can turn that into a pivot table.
    Attached Files Attached Files
    Last edited by rpthoth; 01-31-2012 at 08:01 PM.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Count instances of a string across multiple columns with multiple criteria

    rpthoth,


    Detach/open workbook CountInstances - w1ABCD FGH - rpthoth - EF812220 - SDG16.xls and run the CountInstancess macro.



    If you want to use the macro on another workbook:


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    Please Login or Register  to view this content.

    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


    Then run the CountInstances macro.



    If the macro does not work correctly with your actual raw data, then please attach another workbook with the actual strings in columns B, C and D.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Count instances of a string across multiple columns with multiple criteria

    as an option
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Count instances of a string across multiple columns with multiple criteria

    nilen,

    Nicely done.

    I am still learning to use arrays in memory.

    This is one for my archives.

  5. #5
    Registered User
    Join Date
    12-20-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Count instances of a string across multiple columns with multiple criteria

    Thank you both! I'm reworking some of the coding to fit my spreadsheet and then I'll report back. Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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