Here's one way
In B2
=COUNTIF(INDIRECT("Sheet1!"&ADDRESS(MATCH(B$1,Sheet1!$A:$A,0),1)&":"&ADDRESS(OFFSET(INDIRECT(ADDRESS(MATCH(B$1,Sheet1!$A:$A,0),1)),COUNTIF(Sheet1!$A:$A,B$1),0),8)),ROW($A1))
Drag/Fill Down to Row 50 Then across to Column M
Note
Any month that is not in your sheet "Sheet1" will return #N/A, you could if you want suppress this error with this IF statement in B2
=IF(ISERROR(MATCH(B$1,Sheet1!$A:$A,)),0,COUNTIF(INDIRECT("Sheet1!"&ADDRESS(MATCH(B$1,Sheet1!$A:$A,0),1)&":"&ADDRESS(OFFSET(INDIRECT(ADDRESS(MATCH(B$1,Sheet1!$A:$A,0),1)),COUNTIF(Sheet1!$A:$A,B$1),0),8)),ROW($A1)))
Hope this helps.
There is probably a better way using SUMPRODUCT, or dynamic named ranges, I just can't get my head around them at the moment!
Bookmarks