Solved

VBA to sum a column

Posted on 2016-10-07
13
36 Views
Last Modified: 2016-10-07
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.
0
Comment
Question by:Jagwarman
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 31

Expert Comment

by:Rob Henson
ID: 41833399
Is your formula in the same column as the data?

If not, just use the whole column:

=SUM(L:L)
0
 
LVL 17

Expert Comment

by:Roy_Cox
ID: 41833406
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
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 41833411
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
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 41833412
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
 

Author Comment

by:Jagwarman
ID: 41833414
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
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 41833415
since you have the data on L column, so i updated the example file.
EE.xlsx
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Jagwarman
ID: 41833418
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
 
LVL 17

Assisted Solution

by:Roy_Cox
Roy_Cox earned 250 total points
ID: 41833427
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
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 41833452
@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
 

Author Closing Comment

by:Jagwarman
ID: 41833457
Thanks Experts have a great weekend.
0
 
LVL 31

Expert Comment

by:Rob Henson
ID: 41833463
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
 
LVL 17

Expert Comment

by:Roy_Cox
ID: 41833490
Pleased to help
0
 

Author Comment

by:Jagwarman
ID: 41833510
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now