Summing Columns of Varying Length from a Constant cell to the bottom of the column - 5 rows

amirbp2002

New Member
Joined
Jun 17, 2018
Messages
5
Hi everyone,

I have been trying to figure this out, I need a macro to start from a constant cell in a column (Ex: A12), then sum the column down to the bottom (varying length) as in the command+shift+down keystroke, but shorten the sum selection by 4 cells from the bottom.

So, for instance if the column is filled with numbers down to A1000, the it sums from A12 to A996.

Thank you very much!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi & welcome to MrExcel.
How about
Code:
Sub SumCol()
   Dim rng As Range
   Set rng = Range("A12", Range("A12").End(xlDown).Offset(-4))
   MsgBox Application.SUM(rng)
End Sub
 
Upvote 0
Or actually, it is better the sum value to be printed in another sheet in the same excel (Sheet1), in the first cell (A1), I think that would be easier.

Thanks
 
Upvote 0
How about
Code:
Sub SumCol()
   Dim rng As Range
   With Sheets("[COLOR=#ff0000]Sheet2[/COLOR]")
      Set rng = .Range("A12", .Range("A12").End(xlDown).Offset(-4))
   End With
   Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Range("A1").Value = Application.SUM(rng)
End Sub
Change sheet names in red to suit
 
Upvote 0
Works great! Thank you very much. Just wondering for the future, is there anyway I can record keystrokes in macro excel recorder? I would perform this in the recorder, but it unfortunately only picked up the cell number rather than the key strokes, so I couldn't apply it to a column of varying length.
 
Upvote 0
Also, Can I loop this through lets say 9 columns x spaced apart so it picks up the sum for A column, then do the same for I column, and so on to then print it in A2, A3, and so on in Sheet1?

Thanks
 
Upvote 0
You would not be able to record a sum on a dynamic range, as the recorder is very literal.
But you can record a dynamic range by selecting a start cell & then using Ctrl Shift down arrow
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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