WorksheetFunction.COUNTIF fails on the second pass
Hello,
has anyone encountered with the following problem?
I have a macro that counts non-empty cells in columns. It works on the first pass, but for all consecutive ones shows a "Type Mismatch" error. The code is below:
For i = 2 To numColumns
With wb.Worksheets("Sheet1")
Set r = .Range(.Cells(1, i), .Cells(numRows, i))
.Cells(numRows+1, i) = WorksheetFunction.CountIf(r, ">0")
End With
Next i
Thanks in advance.
|