+ Reply to Thread
Results 1 to 5 of 5

Re: Sum in VBA

  1. #1
    Susan Hayes
    Guest

    Re: Sum in VBA

    Hello

    How can I sum up for example A4 through A16 and have the total appear in A17, i.e., A17 = SUM(A4:A16)

    What is the VBA syntax to get the above.


    Thank you,

    Jen T.


  2. #2
    Don Guillett
    Guest

    Re: Sum in VBA

    Had you tried this in vba you would have gotten an error msg. Then select
    the word sum and use f1 to find out how.

    Sub sumem()
    MsgBox Sum("g5:g10")
    End Sub

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Susan Hayes" <[email protected]> wrote in message
    news:[email protected]...
    > Hello
    >
    > How can I sum up for example A4 through A16 and have the total appear in

    A17, i.e., A17 = SUM(A4:A16)
    >
    > What is the VBA syntax to get the above.
    >
    >
    > Thank you,
    >
    > Jen T.
    >




  3. #3
    Jim Thomlinson
    Guest

    Re: Sum in VBA

    Here is the code:

    ActiveSheet.Range("A17") = Application.Sum(ActiveSheet.Range("A1:A16"))

    This inserts the total. Not a formula.

    HTH

    "Susan Hayes" wrote:

    > Hello
    >
    > How can I sum up for example A4 through A16 and have the total appear in A17, i.e., A17 = SUM(A4:A16)
    >
    > What is the VBA syntax to get the above.
    >
    >
    > Thank you,
    >
    > Jen T.
    >
    >


  4. #4
    Jim Thomlinson
    Guest

    Re: Sum in VBA

    Sorry I got the range wong. It should read

    ActiveSheet.Range("A17") = Application.Sum(ActiveSheet.Range("A4:A16"))

    Oops...

    "Jim Thomlinson" wrote:

    > Here is the code:
    >
    > ActiveSheet.Range("A17") = Application.Sum(ActiveSheet.Range("A1:A16"))
    >
    > This inserts the total. Not a formula.
    >
    > HTH
    >
    > "Susan Hayes" wrote:
    >
    > > Hello
    > >
    > > How can I sum up for example A4 through A16 and have the total appear in A17, i.e., A17 = SUM(A4:A16)
    > >
    > > What is the VBA syntax to get the above.
    > >
    > >
    > > Thank you,
    > >
    > > Jen T.
    > >
    > >


  5. #5
    Patrick Molloy
    Guest

    Re: Sum in VBA

    The answers that you have so far "hard code" th erange to be summed

    The example below adds some flexibility, although for the example I left out
    error handling - you can do that

    I have data in column C starting at line 4, my "test" adds the total

    Option Explicit
    Public Sub Test()
    AddTotals 4, "C"
    End Sub

    Public Sub AddTotals(lFirstRow As Long, sColumn As String)

    With Cells(lFirstRow, sColumn).End(xlDown).Offset(1, 0)

    .FormulaR1C1 = "=SUM(R[-1]C:R" & lFirstRow & "C)"

    End With


    End Sub





    "Susan Hayes" wrote:

    > Hello
    >
    > How can I sum up for example A4 through A16 and have the total appear in A17, i.e., A17 = SUM(A4:A16)
    >
    > What is the VBA syntax to get the above.
    >
    >
    > Thank you,
    >
    > Jen T.
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1