VBA Sumifs

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,501
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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