Human_doing
Board Regular
- Joined
- Feb 16, 2011
- Messages
- 137
Hi all,
This code uses VBA to select all rows with data and place in cell K2 the number of matches in column E between the dates in another worksheet called 'Monthsheet' cells B2 and C2. Can anyone please help with the VBA to extend this so that it adds another criterion, namely that it searches column D and looks for matches to 'Monthsheet' D1 as well?
E.g. if monthsheet b2 is '01/01/2011', monthsheet c2 is '31/12/2011' and D1 is 'C22' then it will look for all data where the date is between B2 and C2 and the corresponding cell in column D matches 'C22'?
Thanks in advance for any help
This code uses VBA to select all rows with data and place in cell K2 the number of matches in column E between the dates in another worksheet called 'Monthsheet' cells B2 and C2. Can anyone please help with the VBA to extend this so that it adds another criterion, namely that it searches column D and looks for matches to 'Monthsheet' D1 as well?
E.g. if monthsheet b2 is '01/01/2011', monthsheet c2 is '31/12/2011' and D1 is 'C22' then it will look for all data where the date is between B2 and C2 and the corresponding cell in column D matches 'C22'?
Thanks in advance for any help
Code:
Dim Sh As Worksheet
Dim LR As Long
For Each Sh In ActiveWorkbook.Worksheets
With Sh
LR = .Range("E" & .Rows.Count).End(xlUp).Row
.Range("K2").Formula = "=SUMPRODUCT((E2:E" & LR & ">MonthSheet!B2)*(E2:E" & LR & "<MonthSheet!C2))"