PDA

View Full Version : trying to count total rows based on group of values in another column



talytech
07-11-2019, 01:49 PM
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

arangogs
07-11-2019, 03:50 PM
Hi Talytech,

A pivot table would provide all you are looking.

talytech
07-11-2019, 05:24 PM
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")

arangogs
07-12-2019, 01:20 AM
Hi Talytech,

No problem. glad you got it.