Error at line Range("PASS/FAIL").Select line is because the PASS/FAIL is not valid Named Range. I assume that PASS/FAIL is a named range in your code which you are referring to. If this is the case change this to a valid Named Range like Pass_Fail and then you can try the following code to get the count......
Sub PASS_FAIL_COUNT()
Dim rng, cell As Range
Dim Pass, Fail As Integer
Set rng = Range("Pass_Fail")
Pass = WorksheetFunction.CountIf(rng, "pass")
Fail = WorksheetFunction.CountIf(rng, "fail")
MsgBox "Pass count is " & Pass
MsgBox "Fail count is " & Fail
End Sub
or like this.......
Assuming that column C contains the Pass or Fail. If not, change the column C in red color to the column of your choice in the code.
Sub PASS_FAIL_COUNT_()
Dim rng, cell As Range
Dim lr, countP, countF As Long
lr = Cells(Rows.count, "C").End(xlUp).Row
Set rng = Range("C2:C" & lr)
For Each cell In rng
If cell = "Pass" Then
countP = countP + 1
Else
countF = countF + 1
End If
Next cell
MsgBox "Pass count is " & countP
MsgBox "Fail count is " & countF
End Sub
Bookmarks