SUM Variable Range / Column

MRNewGuy

New Member
Joined
Aug 2, 2018
Messages
2
Hi all,

I am currently struggling with writing a macro, where I would like the macro to sum the last column, starting from the 2nd till the last row of that column. The column which needs to be summed up (last column), can start from Column G, but is variable. This means the column could also be column H, I, J, etc. The range of the column which needs to be summed up, is variable as well.

I am relatively new to writing macro's, but I'd like to think I almost got the Sub finished (see below). The only thing I can't figure out is what to write on the ?? as marked below. I am hoping that there is someone who could let me know if I am indeed on the right track or that I am way off, and could help me with creating the correct Sub?

Hopefully my explanation makes sense, if not please let me know, as I am "MRNewGuy" for a reason:)

Sub Sum()
'
Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(1, 0).Select
LastRow = Range("A2").End(xlDown).Row
ActiveCell.Formula = "=SUM(??2:??" & LastRow & ")"
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi & welcome to MrExcel.
Is this what you're after
Code:
Sub SumCol()
   Dim Lc As Long
   
   Lc = Range("A1").End(xlToRight).Column
   Range("A2").End(xlDown).Offset(1, Lc - 1).FormulaR1C1 = "=sum(r2c:r[-1]c)"
End Sub
 
Upvote 0
Hi Fluff,

This is indeed what I was after, thank you very much for your fast reply and help! Much appreciated!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,790
Members
451,589
Latest member
Harold14

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