Multiple criteria SUMPRODUCT formula with variable ranges

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

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))"
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top