SUM formula issue

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
I have in column D a sum formula that just counts the total from Column C. Now when I run a macro, A new Column C is added and now Column E is my line with the Sum formulas.
What I am trying to do is have the formula sum up from column C up to the current column.

For example:

F8 has a Sum formula: it should sum up C8:E8. Then a new Column is added and G8 now has the Sum formula and the sum should now run from C8:F8.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If C is always your starting column, then you could add the following after you've inserted the column:
Code:
Dim j as Long
j = cells(8, Columns.Count).End(xltoLeft).Column
cells(8,j).Formula = "=SUM(C8:" & cells(8,j-1) & ")"
 
Upvote 0
Try:
Code:
j = Cells(8, Columns.Count).End(xlToLeft).Column
Cells(8, j).Formula = "=SUM(C8:" & Cells(8, j - 1).Address & ")"
Or post your full code so people reading can better understand the stage you are reaching before encountering your problem
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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