VBA Offset cell in Table

jakobt

Active Member
Joined
May 31, 2010
Messages
337
I have a Table I download often.

I want to make a macro, which first selects the last cell in column H of my table. Then it selects the next cell in column H and inserts a sum formula for the cells in column h above it.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
Sub SumH()

    Cells(Rows.Count, "H").End(xlUp).Offset(1).FormulaR1C1 = "=SUM(R1C:R[-1]C)"
End Sub
 
Last edited:
Upvote 0
Hi Jakobt,

Is selecting the cell an essential part of the macro? because it is not necessary for entering a formula.

Does every row of column H up to the end?

If so then this should work:

Code:
Sub TotalInH()

    Range("H1048576").End(xlUp).Offset(1).Formula = "=SUM(H2:" & Range("H1048576").End(xlUp).Address & ")"

End Sub

Just change the 'H2' to whatever cell is the first data row in the table.

Cheers
JB
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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