How can I count # of rows that match a criteria in multiple cells within the same row?

GEUser

New Member
Joined
Jun 22, 2017
Messages
2
Hello, I've been trying to figure this out on my own and had no luck. What I'm trying to do is sum up # of rows that match across three parameters - Course, Unit, and Activity #s.

I have two sheets with this information:
Sheet 1: Sections
[TABLE="width: 1475"]
<tbody>[TR]
[TD]Document No.[/TD]
[TD]Course[/TD]
[TD]Course Name[/TD]
[TD]Unit[/TD]
[TD]Unit Name[/TD]
[TD]Activity[/TD]
[TD]Activity Name[/TD]
[TD]Section[/TD]
[TD]Section Name[/TD]
[/TR]
[TR]
[TD]T1U1.A1.S1[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]1[/TD]
[TD]Business Dilemmas[/TD]
[/TR]
[TR]
[TD]T1U1.A1.S2[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]2[/TD]
[TD]Dealing with Dilemmas[/TD]
[/TR]
[TR]
[TD]T1U1.A1.S3[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]3[/TD]
[TD]Dealing with Business Dilemma[/TD]
[/TR]
[TR]
[TD]T1U1.A1.S4[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]4[/TD]
[TD]Asking for Advice[/TD]
[/TR]
[TR]
[TD]T1U1.A1.S5[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]5[/TD]
[TD]Core Values[/TD]
[/TR]
[TR]
[TD]T1U1.A1.S6[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]6[/TD]
[TD]Problems and Solutions[/TD]
[/TR]
[TR]
[TD]T1U1.A1[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]
[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S1[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]1[/TD]
[TD]Common Problems at Work[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S2[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]2[/TD]
[TD]Problems in Companies[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S3[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]3[/TD]
[TD]Problem Solving[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S4[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]4[/TD]
[TD]Commonly Confused Words[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S5[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]5[/TD]
[TD]Describing Problems and Solutions[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S6[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]6[/TD]
[TD]Identifiying and Solving Problems[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S7[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]7[/TD]
[TD]Expressing Necessity[/TD]
[/TR]
[TR]
[TD]T1U1.A2.S8[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]8[/TD]
[TD]Making Suggestions[/TD]
[/TR]
</tbody>[/TABLE]

Sheet 2: Activities
[TABLE="width: 1091"]
<tbody>[TR]
[TD]Document No.[/TD]
[TD]Course[/TD]
[TD]Course Name[/TD]
[TD]Unit[/TD]
[TD]Unit Name[/TD]
[TD]Activity[/TD]
[TD]Activity Name[/TD]
[TD]# of Sections[/TD]
[/TR]
[TR]
[TD]T1U1.A1[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]1[/TD]
[TD]Dealing with Dilemmas[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]T1U1.A2[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]1[/TD]
[TD]Responding to Problems[/TD]
[TD]2[/TD]
[TD]Problem Solving[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]T1U2.A1[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]2[/TD]
[TD]Business Plans and Processes[/TD]
[TD]1[/TD]
[TD]Adapting to an Evolving Business[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]T1U2.A2[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]2[/TD]
[TD]Business Plans and Processes[/TD]
[TD]2[/TD]
[TD]Making Business Plans[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]T1U3.A1[/TD]
[TD]1[/TD]
[TD]Managing People and Projects[/TD]
[TD]3[/TD]
[TD]Improving Business Performance[/TD]
[TD]1[/TD]
[TD]Analyzing a Company's Organization[/TD]
[TD]-[/TD]
[/TR]
</tbody>[/TABLE]

In both sheets, Document No. is concatenated from Course, Unit, and Activity columns.

What I'm trying to do is count the # of sections in each activity, which is the number of rows in sheet 1 that match the Course/Unit/Activity #s in Sheet 2.

There are lot of sections (1000+ rows) and a lot of activities (100+) that they belong to, so I'd rather not select the rows using ROWs function manually.

Is there a combination of functions that could do this automatically? I've been searching across Forums reading about SUMPRODUCT, ROW, ROWS, IF and COUNTIF functions, but not able to find a solution that works. To me it seems so simple, but I just can't figure out the right code to compare the two sheets. :-( :-(

Down the line, I also would like to populate Sections sheet (Sheet 1) with Course Name, Unit Name and Activity Name automatically from Activities Sheet (Sheet 2). I think I would need to do a complex VLOOKUP code, but again, how do I refer to multiple matching cells, so that all three values in the same row match (Course #, Unit #, and Activity#)?

Thank you in advance for you help!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
GEU,

Enter this formula in cell H2 of Sheet 2.
=COUNTIFS(Sheet1!B2:B16,Sheet2!B2,Sheet1!D2:D16,Sheet2!D2,Sheet1!F2:F16,Sheet2!F2,Sheet1!H2:H16,">0")

That formula currently only evaluates Rows 2-16 per your example. You would need to expand that to encompass all rows you are trying to evaluate.
The last evaluation: H2:H16,">0" I added since there was a 7th row that matched the first three equations but there was no number in the Section Column so I assumed you didn't want to count that row.
You can delete that from your formula if you want to count that row.
 
Upvote 0
GEU

I made one mistake. At a minimum, the rows on these Sheet1 ranges must be set to absolute to maintain the integrity of the Ranges when you copy the formula down to other rows.
In the updated formula below I set both Column and Row as Absolute.

=COUNTIFS(Sheet1!$B$2:$B$16,Sheet2!B2,Sheet1!$D$2:$D$16,Sheet2!D2,Sheet1!$F$2:$F$16,Sheet2!F2,Sheet1!$H$2:$H$16,">0")
 
Upvote 0
Thank you for the response frank_AL! Not sure why, but this formula returns a value of 0.

I want to post for all a solution offered by my colleague at work:
Step 1) Insert a new column and create a concatenated code in Sheet1 just for the activity # ("a key").
Step 2) Create a pivot table (in a separate sheet) to count all instances of the key in Sheet1,
Step 3) Paste Pivot table values into Sheet 2 (preferably just the values, not the formula).
Step 4) Delete unnecessary sheets and columns once the calculation is complete for all rows.

It takes a few steps, but did achieve the intended result.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top