Using Sumifs in VBA where range changes

cwilliams96

Board Regular
Joined
Jul 27, 2003
Messages
186
Hi

I am using a simply Sumifs formula, however this is across a data range that will change

This is the formula and works as is

Range("L6").Select
ActiveCell.Formula = "=SUMIFS('Apps Indicative Earnings Report'!$K$11:$K$73,'Apps Indicative Earnings Report'!$G$11:$G$73,'INVOICE CALC'!H6,'Apps Indicative Earnings Report'!$C$11:$C$73,'INVOICE CALC'!J6,'Apps Indicative Earnings Report'!$D$11:$D$73,'INVOICE CALC'!K6)"

however it wont always be row 73 it sums along. The rows may be greater or smaller next time

I have counted the numnber of rows in the data and stored this as in integer in variable "i"..

I am a real novice at VBA, so thought it may be as simple as replacing "$K$11:$K$73" with "$K$11:$K$ & i" - but of course it isnt :(

I could simply leave a massive range in the formula, but would rather not.

Any help would be appreciated

Thanks

Chris
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I have counted the numnber of rows in the data and stored this as in integer in variable "i"..
Then try the following. Note that there is no need to select the cell to put a formula in it.

Code:
Range("L6").Formula = Replace("=SUMIFS('Apps Indicative Earnings Report'!$K$11:$K$#,'Apps Indicative Earnings Report'!$G$11:$G$#,'INVOICE CALC'!H6,'Apps Indicative Earnings Report'!$C$11:$C$#,'INVOICE CALC'!J6,'Apps Indicative Earnings Report'!$D$11:$D$#,'INVOICE CALC'!K6)", "#", i)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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