M
mlthornton
Hello! I'm running into a problem using the the Countif function in a VBA code. If I type =countapples() into cell A1 of Sheet1, it returns the expected answer. See countapples() function below:
________________________________________________
Function CountApples()
Dim TopOfRange As Double
Dim BottomOfRange As Double
TopOfRange = 4
BottomOfRange = 10
Set SearchRange = Worksheets("Sheet1").Range(Cells(TopOfRange, 1), Cells(BottomOfRange, 100))
ReturnCount = Application.WorksheetFunction.CountIf(SearchRange, "apple")
CountApples = ReturnCount
End Function
________________________________________________
BUT if I type =CountApples() into cell A1 of Sheet2, it returns #VALUE!
What's the problem with this code? Can CountIf not work across sheets?
________________________________________________
Function CountApples()
Dim TopOfRange As Double
Dim BottomOfRange As Double
TopOfRange = 4
BottomOfRange = 10
Set SearchRange = Worksheets("Sheet1").Range(Cells(TopOfRange, 1), Cells(BottomOfRange, 100))
ReturnCount = Application.WorksheetFunction.CountIf(SearchRange, "apple")
CountApples = ReturnCount
End Function
________________________________________________
BUT if I type =CountApples() into cell A1 of Sheet2, it returns #VALUE!
What's the problem with this code? Can CountIf not work across sheets?