Consulting

Results 1 to 8 of 8

Thread: Solved: Sum of columns

  1. #1
    Banned VBAX Regular
    Joined
    Mar 2007
    Posts
    13
    Location

    Solved: Sum of columns

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =SUM(A:A)

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

  3. #3
    Banned VBAX Regular
    Joined
    Mar 2007
    Posts
    13
    Location
    its giving a "Compiler error"

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It's not VBA, VBA is overkill for that.

    If you must VBA

    [vba]

    MsgBox Application.Sum(Range("A:A"))
    [/vba]

  5. #5
    Banned VBAX Regular
    Joined
    Mar 2007
    Posts
    13
    Location
    I need to display the result in the column which is empty.. not in the form of a mesgbox

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can't you work that out yourself, don't you know any VBA?

    ANd why not just a formula direct in the worksheet?

  7. #7
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Try:
    [VBA]
    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
    [/VBA]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
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  8. #8
    Banned VBAX Regular
    Joined
    Mar 2007
    Posts
    13
    Location
    Thanks .. that helped a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •