How to let last row stay when data overflows using VBA

Cicyhua

New Member
Joined
Aug 27, 2014
Messages
6
Hi I need your help again.
How to keep my grand total stay at the bottom of my table even if data overflows? For example, when I have 20 rows of data, my grand total row stays at the 21th row, when I have 50 rows of data, my grand total row stays at the 51th without making any manual changes. I need a vba code or anything that can make this works. Thanks!!!!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Do you mean like this where run a macro, and it summs the column?
(change J2 to the col. you need.)

Code:
Sub SumAll()
Dim r As Long
    Range("J2").Select
    Selection.End(xlDown).Select
    r = ActiveCell.Row
    ActiveCell.Offset(1, 0).Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-" & r & "]C:R[-1]C)"
End Sub
 
Upvote 0
Thank you very much! I need something like this. How do I write the code for multiple columns because I have to sum 5 columns.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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