PDA

View Full Version : Solved: Sum of columns



Sreeja
04-19-2007, 04:20 AM
Hi,
I am trying to create a maro to get the sum of a column... however the range of the column is not specified .. to i need to check till the end of the column and then add them

Bob Phillips
04-19-2007, 04:21 AM
=SUM(A:A)

will sum everything in column A, no need to specify the end.

Sreeja
04-19-2007, 04:34 AM
its giving a "Compiler error"

Bob Phillips
04-19-2007, 04:38 AM
It's not VBA, VBA is overkill for that.

If you must VBA



MsgBox Application.Sum(Range("A:A"))

Sreeja
04-19-2007, 04:50 AM
I need to display the result in the column which is empty.. not in the form of a mesgbox

Bob Phillips
04-19-2007, 04:53 AM
Can't you work that out yourself, don't you know any VBA?

ANd why not just a formula direct in the worksheet?

Simon Lloyd
04-19-2007, 05:14 AM
Try:

Option Explicit
Sub Column_sum()
Dim Rng As Range
Dim MyVal As Integer
Set Rng = ActiveSheet.Range("A1").End(xlDown)
MyVal = Application.WorksheetFunction.Sum(ActiveSheet.Range("A1:" & Rng.Address))
Rng.Offset(1, 0).Value = MyVal
End Sub
it will put the sum at the bottom of each column , but from this code you will be able to work out how to send the value to another location!
regards,
Simon

Sreeja
04-23-2007, 02:34 AM
Thanks .. that helped a lot
:)