Counting rows with specific number of populated cells

gowildcats

New Member
Joined
Jul 7, 2015
Messages
3
I want to count the number of rows that have a specific number of populated cells. For example looking at the table below, I want to know the number of rows that have "Yes" exactly 2 times. I only care about text though that's in columns C, D, E, and F (A, B, G, and H should not be included in my count). Eventually I want to replicate this same formula to count the number of cells in C through F that have 3 cells populated as well. My actual data has over 500 total rows and is formatted in a table. I've tried using different combos of CountIF and CountA but can't figure out the right equation combo.

[TABLE="width: 634"]
<colgroup><col><col span="8"></colgroup><tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD]Yes[/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]Yes[/TD]
[TD]Yes[/TD]
[TD]Yes[/TD]
[TD]Yes[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:
Code:
Sub countYes()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim x As Long
    Dim y As Long
    y = 0
    For x = 1 To LastRow
        If WorksheetFunction.CountIf(Range("C" & x & ":F" & x), "Yes") = 2 Then
            y = y + 1
        End If
    Next x
    MsgBox (y & " rows contain 2 occurrences of Yes.")
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
if you don't want VBA and can tolerate a helper column, here is one way to go:


Excel 2012
ABCDEFGHIJ
1rows with No of "Yes"
21234
32311
4# of "Yes"
5YesYesYes3
6Yes1
7YesYes2
80
9YesYes2
10YesYes2
11Yes1
12YesYesYesYes4
Sheet63
Cell Formulas
RangeFormula
G3=COUNTIF($F:$F,G2)
H3=COUNTIF($F:$F,H2)
I3=COUNTIF($F:$F,I2)
J3=COUNTIF($F:$F,J2)
F5=COUNTIF(A5:D5,"=yes")
F6=COUNTIF(A6:D6,"=yes")
F7=COUNTIF(A7:D7,"=yes")
F8=COUNTIF(A8:D8,"=yes")
F9=COUNTIF(A9:D9,"=yes")
F10=COUNTIF(A10:D10,"=yes")
F11=COUNTIF(A11:D11,"=yes")
F12=COUNTIF(A12:D12,"=yes")
 
Upvote 0
Thanks! Anyway to do it in excel (not VBA) without a helper column? Will settle for the extra column if I have to, but anyway to code it without?
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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