Count Cells with Specific Text in Multiple Columns without Double Counting

jessebh2003

Board Regular
Joined
Feb 28, 2020
Messages
71
Office Version
  1. 365
Platform
  1. Windows
I'm trying to write a formula that will count the number of rows that contain "Yes" or "No" in multiple columns. However, if more than one column for the same row contains "Yes" or "No" I only want the row to be counted once. Here's what I've tried:

Excel Formula:
=SUM(ISNUMBER(MATCH(Data!$AQ$3:$AQ$1000, Data!$BA$3:$BA$1000, Data!$BK$3:$BK$1000, Data!$BU$3:$BU$1000, Data!$CE$3:$CE$1000, Data!$CD$3:$CD$1000, Data!$CV$3:$CV$1000, Data!$DI$3:$DI$1000, Data!$DS$3:$DS$1000, Data!$EC$3:$EC$1000, Data!$EN$3:$EN$1000{"Yes","No"},0)))
This gives me the error "You've entered too many arguments for this function."

Excel Formula:
=SUMPRODUCT(--((Data!$AQ$3:$AQ$1000 = "Yes","No")+(Data!$BA$3:$BA$1000 = "Yes","No")+(Data!$BK$3:$BK$1000 = "Yes","No")+(Data!$BU$3:$BU$1000 = "Yes","No")+(Data!$CE$3:$CE$1000 = "Yes","No")+(Data!$CD$3:$CD$1000 = "Yes","No")+(Data!$CV$3:$CV$1000 = "Yes","No")+(Data!$DI$3:$DI$1000 = "Yes","No")+(Data!$DS$3:$DS$1000 = "Yes","No")+(Data!$EC$3:$EC$1000 = "Yes","No")+(Data!$EN$3:$EN$1000 ="Yes","No"),>0))
This gives me a 0 even though there is text in the specified columns.

Both of these codes Then I need to count all of the cells in the came columns that contain "Yes" and then "No". So I tried:
Excel Formula:
=COUNTIFS(Data!$AQ$3:$AQ$1000,Data!$BA$3:$BA$1000,Data!$BK$3:$BK$1000,Data!$BU$3:$BU$1000,Data!$CE$3:$CE$1000,Data!$CD$3:$CD$1000,Data!$CV$3:$CV$1000,Data!$DI$3:$DI$1000,Data!$DS$3:$DS$1000,Data!$EC$3:$EC$1000,Data!$EN$3:$EN$1000,"Yes")
This gave me an alert saying that the formula returned multiple results and spilled over into other cells giving me 998 cells of 0.

Can anyone help me fix these? Thanks!!
 
Oops, missed that your data started in B1 & not A1.
Having changed that I get
+Fluff 1.xlsm
JK
9Yes1
10No0
11Both0
Summary


Check that your cells with Yes or No don't have any leading/trailing spaces or other hidden characters.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Oops, missed that your data started in B1 & not A1.
Having changed that I get
+Fluff 1.xlsm
JK
9Yes1
10No0
11Both0
Summary


Check that your cells with Yes or No don't have any leading/trailing spaces or other hidden characters.
I checked and there are no spaces or other characters and ran the macro again and still got zeros. I even repasted the code into the module but still zeros.

TestEvalData.xlsx
JK
9Yes0
10No0
11Both0
Summary

TestEvalData.xlsm
JK
9Yes0
10No0
11Both0
Summary
 
Upvote 0
Do you have the code in a standard module, or in a Sheet Module or the ThisWorkbook Module?
 
Upvote 0
Ok, what if you try
VBA Code:
Sub jessebh()
   Dim Ary As Variant, Nary(1 To 3) As Long
   Dim r As Long, c As Long
   Dim y As Boolean, n As Boolean
   
   Ary = ActiveWorkbook.Sheets("Data").Range("AQ3:EN1000").Value2
   For r = 1 To UBound(Ary)
      For c = 1 To 101 Step 10
         If LCase(Ary(r, c)) = "yes" And Not y Then
            Nary(1) = Nary(1) + 1
            If n Then Nary(3) = Nary(3) + 1
            y = True
         ElseIf LCase(Ary(r, c)) = "no" And Not n Then
            Nary(2) = Nary(2) + 1
            If y Then Nary(3) = Nary(3) + 1
            n = True
         End If
         If y And n Then Exit For
      Next c
      y = False
      n = False
   Next r
   ActiveWorkbook.Sheets("Summary").Range("J9:K11").Value = Application.Transpose(Array(Array("Yes", "No", "Both"), Nary))
End Sub
 
Upvote 0
Solution
Ok, what if you try
VBA Code:
Sub jessebh()
   Dim Ary As Variant, Nary(1 To 3) As Long
   Dim r As Long, c As Long
   Dim y As Boolean, n As Boolean
  
   Ary = ActiveWorkbook.Sheets("Data").Range("AQ3:EN1000").Value2
   For r = 1 To UBound(Ary)
      For c = 1 To 101 Step 10
         If LCase(Ary(r, c)) = "yes" And Not y Then
            Nary(1) = Nary(1) + 1
            If n Then Nary(3) = Nary(3) + 1
            y = True
         ElseIf LCase(Ary(r, c)) = "no" And Not n Then
            Nary(2) = Nary(2) + 1
            If y Then Nary(3) = Nary(3) + 1
            n = True
         End If
         If y And n Then Exit For
      Next c
      y = False
      n = False
   Next r
   ActiveWorkbook.Sheets("Summary").Range("J9:K11").Value = Application.Transpose(Array(Array("Yes", "No", "Both"), Nary))
End Sub

That worked great! Here's what I got.

TestEvalData.xlsm
JK
9Yes8
10No5
11Both2
Summary


I then added the formula
Excel Formula:
=SUM(K9:K11)-(K11*2)
to get my total rows without double counting. Thank you so much for your help with this! I truly appreciate it!
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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