Hi, I’m new to VBA and I’m trying to modify the code below.
I have a large workbook with separate sheets assigned to different products. Eachsheet has numerous date entries. I’d like to have the macro count the number ofentries per month in “Sheet1” with the output in “Sheet11”.
The code below works if the dates and the output are in thesame active worksheet, however, when I try to assign “a” to Sheet1 and “itm” to“Sheet11” I get a compile error.
“E2” is equal to “2019”
Any help will be very much appreciated.
Sub MonthlyCount()
Dim a As Variant, itm As Variant
Dim b(1 To 12, 1 To 1) As Long, myYear As Long
a = Sheet1.Range("A23", Range("A" &Rows.Count).End(xlUp)).Value
myYear = Range("E2").Value
For Each itm In a
IfSheet11.Year(itm) = myYear Then b(Month(itm), 1) = b(Month(itm), 1) + 1
Next itm
Range("C2").Resize(12).Value = b
End Sub
I have a large workbook with separate sheets assigned to different products. Eachsheet has numerous date entries. I’d like to have the macro count the number ofentries per month in “Sheet1” with the output in “Sheet11”.
The code below works if the dates and the output are in thesame active worksheet, however, when I try to assign “a” to Sheet1 and “itm” to“Sheet11” I get a compile error.
“E2” is equal to “2019”
Any help will be very much appreciated.
Sub MonthlyCount()
Dim a As Variant, itm As Variant
Dim b(1 To 12, 1 To 1) As Long, myYear As Long
a = Sheet1.Range("A23", Range("A" &Rows.Count).End(xlUp)).Value
myYear = Range("E2").Value
For Each itm In a
IfSheet11.Year(itm) = myYear Then b(Month(itm), 1) = b(Month(itm), 1) + 1
Next itm
Range("C2").Resize(12).Value = b
End Sub