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

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
810
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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
OH MY GOD I MISPELLED INDIRECT COST RAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


Thanks Rory.
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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