VBA - Summing a dynamic gap range between two named ranges?

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
790
Office Version
  1. 365
Platform
  1. Windows
Hi all, can't even figure out how to phrase this in Google or ChatGPT to get something that is nice and clean.

I have a sheet where in column J, there are costs, and sub-totals for those costs.

Each subtotal is a named range, for instance:
"DirectCostSum" is J23
"IndirectCostSum" is J31

What I'd like to do is for IndirectCostSum cell value to be a sum of J24:J30.

These subtotals are dynamically placed based on how many products I am summing, so the gap between the named ranges I want to sum is always changing.

What I'm after is a nice, one line chunk of code which will be like..

VBA Code:
range("IndirectCostSum").formular1c1 = "=SUM( [DirectCostSum + 1],[IndirectCostSum -1]),

That's the best way I can describe it lol. Hopefully that makes sense.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
OH MY GOD I MISPELLED INDIRECT COST RAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


Thanks Rory.
 
Upvote 0
o_O:unsure::ROFLMAO:

at least now we know!
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,977
Members
449,095
Latest member
Mr Hughes

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