VBA Sumifs

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,516
Office Version
  1. 2016
Platform
  1. Windows
Hi friends,

How to write this formula in VBA....

=IF(AND($C$1="ALL",$C$2="ALL"),SUMIFS(orders_quantity,orders_po_shipment_date,">="&F$2,orders_po_shipment_date,"<="&F$4,orders_ref,$B11),IF(AND($C$1="ALL",$C$2<>"ALL"),SUMIFS(orders_quantity,orders_supplier,$C$2,orders_po_shipment_date,">="&F$2,orders_po_shipment_date,"<="&F$4,orders_ref,$B11),IF(AND($C$1<>"ALL",$C$2="ALL"),SUMIFS(orders_quantity,orders_customer,$C$1,orders_po_shipment_date,">="&F$2,orders_po_shipment_date,"<="&F$4,orders_ref,$B11),IF(AND($C$1<>"ALL",$C$2<>"ALL"),SUMIFS(orders_quantity,orders_supplier,$C$2,orders_customer,$C$1,orders_po_shipment_date,">="&F$2,orders_po_shipment_date,"<="&F$4,orders_ref,$B11),""))))

I only want the result not the formula in range H11 to H403.

Regards,

Humayun
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You could do it like this:

Code:
With Range("H11:H403")
    .Formula = "=IF(AND($C$1=""ALL"",$C$2=""ALL""),SUMIFS(orders_quantity,orders_po_shipment_date,"">=""&F$2,orders_po_shipment_date,""<=""&F$4,orders_ref,$B11),IF(AND($C$1=""ALL"",$C$2<>""ALL""),SUMIFS(orders_quantity,orders_supplier,$C$2,orders_po_shipment_date,"">=""&F$2,orders_po_shipment_date,""<=""&F$4,orders_ref,$B11),IF(AND($C$1<>""ALL"",$C$2=""ALL""),SUMIFS(orders_quantity,orders_customer,$C$1,orders_po_shipment_date,"">=""&F$2,orders_po_shipment_date,""<=""&F$4,orders_ref,$B11),IF(AND($C$1<>""ALL"",$C$2<>""ALL""),SUMIFS(orders_quantity,orders_supplier,$C$2,orders_customer,$C$1,orders_po_shipment_date,"">=""&F$2,orders_po_shipment_date,""<=""&F$4,orders_ref,$B11),""""))))"
    .Value = .Value
End With
 
Upvote 0
Hi Stephen,

Thanks for the solution... Its working OK

But, its taking more or less same time as with the formulas in there. Is there a better way to handle it - to make it work faster

Regards,

Humayun
 
Upvote 0
Have you turned off screenupdating and turned calculation to manual ?
 
Upvote 0
Hello Micheal,

Yes I did at the start of the code and turned it back on at the end of the code.

Still with formulas in there works a bit faster as compared to VBA..

Regards,

Humayun
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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