Lure
Second attempt at answering your question.
First you are using a worksheet function countif in your vba in the form
worksheetfunction.countif( rng , 1 )
and rng
is required to be a single range.
Next you are using the methods Sheets("Sheet1").Range("A2:A645").SpecialCells(xlCellTypeVisible)
specifically SpecialCells, which is returning a range, but the range is not a single continguous block. Instead, if you debug through your code, and put a watch on this range, then you see that the property Areas actually has a count of 2.
Set rng = Sheets("Sheet1").Range("b2:b645").SpecialCells(xlCellTypeVisible)
Set areaCount = rng.Areas.Count
So the problem is not with your CountIf method, but rather that the Range you are passing into CountIf is made up of different ranges, ie it is of the wrong type.
CountIf can therefore not work for you in this scenario. What you need to use is a worksheet function that allows for working with filtered datasets.
So the function Subtotal which does take a list of ranges seems to be a more appropriate WorksheetFunction for your needs. Now you need to choose an appropriate Aggregate method for the first parameter, which for you is 2 or 3. Count numbers only : 2 or count none blank cells : 3.
Usefully the Aggregate function provides a list of aggregations you can use.
You can now also use the Aggregate function or Subtotal function to Sum your visible ranges, by using the Aggregate function Sum : 9.
Putting all of this together here is a suggested code snippet for you..
Sub test31()
Dim rngToUse As Range
Dim visibleSum As Long
Dim countOfVisible As Long
Set rngToUse = Sheets("Sheet1").Range("b2:b645")
visibleSum = WorksheetFunction.Subtotal(9, rngToUse)
countOfVisible = WorksheetFunction.Subtotal(3, rngToUse)
Debug.Print "Sum Visible Cells only: " & visibleSum
Debug.Print "Count of Visible Cells : " & countOfVisible
If countOfVisible > 0 Then
Debug.Print "Ok"
End If
End Sub
I hope that was a little more useful and informative.
Regards
Gareth