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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
2,235
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

Cicyhua

New Member
Joined
Aug 27, 2014
Messages
6
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,195,673
Messages
6,011,087
Members
441,581
Latest member
rp4717

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
Top