kajohnson9
New Member
- Joined
- Jul 29, 2011
- Messages
- 9
I have a function using COUNTIF where I want to count the number of occurrances of a number (input value) across multiple sheets. I thought this would be straightforward but I can't get it to execute. All I get is a beep when I try. Any help you can give me is appreciated. The code is as follows and it is called from a cell as =countbyyear(F5) where F5 contains a number, like 2024.
VBA Code:
Function CountByYear(myYear)
Dim s$, ws As Worksheet
Dim EachCount As Integer
CountByYear = 0
For Each ws In Worksheets
If UCase$(ws.Name) <> "TOC" Then
EachCount = WorksheetFunction.CountIf(Range("C3:C200"), myYear)
CountByYear = CountByYear + EachCount
End If
Next
End Function
Last edited by a moderator: