Solved

VBA to sum a column

Posted on 2016-10-07
13
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 33

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 19

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 26

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 51

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 26

Expert Comment

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

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 19

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 26

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 33

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 19

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

737 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