SUMIF in VBA

Carl Clements

Board Regular
Joined
Jun 13, 2008
Messages
95
Hi,

Is it possible to code a formula such as a SUMIF in VBA to look in a column from cell T2 until the row number previously counted, rather than selecting the whole column?

The reason I'm not selecting the column only is because I have merged cells in row 1 above

I currently have the formula below:

SUMIF(Database!S2:S63,'LODH OTC Recon'!C9,Database!Y2:Y63)

but would like to replace the S63 and Y63 with number of rows counted and stored as the variable 'CountROWS'

I thought the following code would work but unfortunately not

SUMIF(Database!T2:T & CountROWS,'LODH OTC Recon'!RC[-5],Database!T2:T & CountROWS))

Thanks,
Carl
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try like this

Code:
Range("A1").Formula = "SUMIF(Database!S2:" & countrows & ",'LODH OTC Recon'!C9,Database!Y2:Y" & countrows & ")"
 
Upvote 0
Hi Carl

DO you want the range to extend from T2 to the row above where the formula is entered? R1C1 style refs is ideal for this:

Code:
Range("X2:X1000").FormulaR1C1 = "=SUMIF(Database!R2C20:R[-1]C20,'LODH OTC Recon'!RC[-5],Database!R2C20:R[-1]C20)"

Note that I wasn't sure about your second formula as it referenced the same range in both 1st and third arguments, but I have left it as is.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,487
Members
452,917
Latest member
MrsMSalt

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