VBA to sum a column

Need an experts help please to sum a column.

Column L will have various amounts of data each day. Today 3000 items tomorrow 10000 items following day 2000 items.

I need to go to the end on the data offset 1 and then sum sum the column

Would appreciate some help.
JagwarmanAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Rgonzo1971Connect With a Mentor Commented:
Hi,

pls try

Sub SumColL()

Set myRng = Range(Cells(1, 12), Cells(Rows.Count, 12).End(xlUp))
myRng.Offset(myRng.Rows.Count).Resize(1).Formula = "=SUM(" & myRng.Address(0, 0) & ")"
End Sub

Open in new window

Regards
1
 
Rob HensonFinance AnalystCommented:
Is your formula in the same column as the data?

If not, just use the whole column:

=SUM(L:L)
0
 
Roy CoxGroup Finance ManagerCommented:
If you want VBA then try this

Option Explicit

Sub SumL()
Dim rRng As Range

Set rRng = Range(Cells(1, 12), Cells(Rows.Count, 12).End(xlUp))

rRng.Offset(1).Formula = Application.WorksheetFunction.Sum(rRng)
End Sub

Open in new window

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
ProfessorJimJamCommented:
you can use the dynamic range inside the formula

like this

lets say your daya starts from A2 to the last cell that has data

use this formula =SUM(INDIRECT("A2:A"&MATCH(2,INDEX(1/(A:A<>""),))))

see atached.
EE.xlsx
0
 
JagwarmanAuthor Commented:
Hi Roy Cox.

what your code is doing is changing every cell from L2 down to the same amount instead of adding them to come to a total

£118.16
£118.16
£118.16
£118.16
£118.16
£118.16
£118.16
£118.16
0
 
ProfessorJimJamCommented:
since you have the data on L column, so i updated the example file.
EE.xlsx
0
 
JagwarmanAuthor Commented:
Rob Henson & Prof JimJam

Because I need the total to be in the same column [in the first cell after the last item] I cannot use your formula
0
 
Roy CoxConnect With a Mentor Group Finance ManagerCommented:
Try this amendment

Option Explicit

Sub SumL()
Dim rRng As Range

Set rRng = Range(Cells(1, 12), Cells(Rows.Count, 12).End(xlUp))
Cells(Rows.Count, 12).End(xlUp).Offset(1).Formula = Application.WorksheetFunction.Sum(rRng)
End Sub

Open in new window

0
 
ProfessorJimJamCommented:
@Jagwarman

Rob Henson & Prof JimJam

Because I need the total to be in the same column [in the first cell after the last item] I cannot use your formula

in that case then Rgonzo's macro is best fit for you

https://www.experts-exchange.com/questions/28974978/VBA-to-sum-a-column.html?anchor=a41833418#a41833412
0
 
JagwarmanAuthor Commented:
Thanks Experts have a great weekend.
0
 
Rob HensonFinance AnalystCommented:
Are you doing this update frequently?

If not, why use a macro at all?  Select L2 and press End and then Down arrow and down arrow again, then click on the Autosum button on the far right of the home ribbon, Sigma symbol. This will populate the cell with a sum of everything above. Press enter to confirm.

No VBA invoked so no worry about the Undo history being lost.

Thanks
Rob H
0
 
Roy CoxGroup Finance ManagerCommented:
Pleased to help
0
 
JagwarmanAuthor Commented:
Hi Rob,

Yes I am familiar with your proposal but as always with my requests they are part of a much bigger report that uses VBA to do lots of splitting, merging, formulas etc.

Regards
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.