Consulting

Results 1 to 4 of 4

Thread: trying to count total rows based on group of values in another column

  1. #1

    trying to count total rows based on group of values in another column

    I've been wrecking my brain for 2 days trying to figure out how to return the number of rows based on a value in another column. For an example, in the sample table I want to count the total rows in STC where the MCode is "BB".

    I should return 2 for "BB" and 2 for "BS". I can't seem to figure out the best VBA approach to do this. Any help is appreciated.

    STC MCode
    140 BB
    250 BB
    360 BS
    500 BS


  2. #2
    VBAX Regular arangogs's Avatar
    Joined
    Jun 2009
    Location
    Ayrshire, Scotland
    Posts
    18
    Location
    Hi Talytech,

    A pivot table would provide all you are looking.
    Attached Images Attached Images

  3. #3
    Quote Originally Posted by arangogs View Post
    Hi Talytech,

    A pivot table would provide all you are looking.
    Thanks
    arangogs, but I need to use the VBA approach. I figured it out.
    I am using the Application.WorksheetFunction.CountIf

    ct = Application.WorksheetFunction.CountIf(tmpSTC.Range("c1:c20), "BB")

  4. #4
    VBAX Regular arangogs's Avatar
    Joined
    Jun 2009
    Location
    Ayrshire, Scotland
    Posts
    18
    Location
    Hi Talytech,

    No problem. glad you got it.

Posting Permissions

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