Count Rows

admiral100

Well-known Member
Joined
Jan 17, 2015
Messages
873
Hi,

I am looking for a formula or VBA that count only the rows containing the word Yes.
In this example the result should be 3 (row 1,3,4)

A B C
Yes No1 No
No No 2 No
Yes Yes3 Yes
No No4 Yes

<colgroup><col width="70" span="3" style="width:52pt"> </colgroup><tbody>
</tbody>

Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

I am looking for a formula or VBA that count only the rows containing the word Yes.
In this example the result should be 3 (row 1,3,4)

A B C
Yes No1 No
No No2 No
Yes Yes3 Yes
No No4 Yes

<tbody>
</tbody>

Thanks
Hi admiral100, are you opposed to using a helper column? That will be the easiest way of doing it.

In column D (or a hidden helper column): =IF(COUNTIF(A1:C1,"Yes")>0,1,0)
At the bottom of that helper column you can have =COUNTIF(D1:D4,1)

You can update the bold red ranges to suit your data

Excel 2010
ABCDE
1YesNoNo1<--- =IF(COUNTIF(A1:C1,"Yes")>0,1,0)
2NoNoNo0
3YesYesYes1
4NoNoYes1
53<--- =COUNTIF(D1:D4,1)

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
 
Upvote 0
this appears to work for me on your example data

Code:
=COUNTIFS(A1:C4,"yes")

EDIT on test of larger data it collapses SORRY
 
Last edited:
Upvote 0
Hi AkaTrouble ,
your formula returns the value 5

5 cell in the range that contain the word Yes...
 
Upvote 0
maybe something like...

=SUM(IF(FREQUENCY(IF(A1:C4="yes",ROW(A1:A4)-ROW(A1)+1),ROW(A1:A4)-ROW(A1)+1),1)) control shift enter
 
Upvote 0
If you want a code based suggestion, try:
Code:
Sub YesCount()
    
    Dim x       As Long
    Dim y       As Long
    Dim a       As Long
    Dim arr()   As Variant

    Const YES   As String = "Yes"
    
    arr = Cells(1, 1).CurrentRegion.value
    
    For y = LBound(arr, 2) To UBound(arr, 2)
        For x = LBound(arr, 1) To UBound(arr, 1)
            If arr(x, y) = YES Then
                a = a + 1
                Exit For
            End If
        Next x
    Next y
    
    Erase arr
    
    If a > 0 Then MsgBox "Number of rows with ""Yes"" " & vbCrLf & vbCrLf & a, vbOKOnly
                         
End Sub
 
Upvote 0
Hi Fishboy ,

In this case I prefer only one formula or code....
thanks anyway :)
Try:

Code:
Sub CountYesRows()
Dim Cell As Range, cRange As Range, TotalRows As Integer
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set cRange = Range("A1:A" & LastRow)
For Each Cell In cRange
    If Application.WorksheetFunction.CountIf(Range("A" & Cell.Row, "C" & Cell.Row), "Yes") > 0 Then
        TotalRows = TotalRows + 1
    End If
Next Cell
Range("A" & LastRow + 1).Value = TotalRows
End Sub

This will allow your list to get as long as required. If the columns go further across than C, just change the "C" & Cell.Row to the correct letter.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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