+ Reply to Thread
Results 1 to 4 of 4

VBA Sum

  1. #1
    Registered User
    Join Date
    01-17-2006
    Posts
    2

    VBA Sum

    I have an excel file where the number of rows can vary. I need to summarize column B, C and D. The numbers starts at row 3 and there can be blank cells in column B, C and/or D where values are missing. In column A there is a text for each row (even those rows without values). To further explain this:

    Example column A3 to A98 has values, therefore column B, C and D should be summarized with the sum written beneath each row for the columns 3 to 98. In the columns B, C and D there can be randomly empty cells (this should not cause a problem with the sum function)

    After the summaration of column B, C and D I want to take the summarized value in column D and divide it with the summarized value in column B, the result should be presented on the same row and in column E (in the example the row would be E99)

    I can get hold of the last row:
    lastRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

    But I don’t manage to summarize the values in the columns and present the result beneath each row.

    I hope that my explanation is clear enough

    /Fredrik

  2. #2
    Bob Phillips
    Guest

    Re: VBA Sum

    iLastRow = Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row
    Cells(iLastRow + 1, "B").Formula = "=SUM(B3:B" & iLastRow & ")"
    Cells(iLastRow + 1, "D").Formula = "=SUM(D3:D" & iLastRow & ")"
    Cells(iLastRow + 1, "E").Formula = "=D" & iLastRow + 1 & "/B" & iLastRow
    + 1


    --
    HTH

    RP
    "Arbin" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I have an excel file where the number of rows can vary. I need to
    > summarize column B, C and D. The numbers starts at row 3 and there can
    > be blank cells in column B, C and/or D where values are missing. In
    > column A there is a text for each row (even those rows without values).
    > To further explain this:
    >
    > Example column A3 to A98 has values, therefore column B, C and D should
    > be summarized with the sum written beneath each row for the columns 3 to
    > 98. In the columns B, C and D there can be randomly empty cells (this
    > should not cause a problem with the sum function)
    >
    > After the summaration of column B, C and D I want to take the
    > summarized value in column D and divide it with the summarized value in
    > column B, the result should be presented on the same row and in column E
    > (in the example the row would be E99)
    >
    > I can get hold of the last row:
    > lastRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    >
    > But I don't manage to summarize the values in the columns and present
    > the result beneath each row.
    >
    > I hope that my explanation is clear enough
    >
    > /Fredrik
    >
    >
    > --
    > Arbin
    > ------------------------------------------------------------------------
    > Arbin's Profile:

    http://www.excelforum.com/member.php...o&userid=30542
    > View this thread: http://www.excelforum.com/showthread...hreadid=501953
    >




  3. #3
    Gary Keramidas
    Guest

    Re: VBA Sum

    you can give this a try

    Option Explicit
    Sub test()
    Dim lastrow As Long
    lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row

    Range("A" & lastrow + 1).Formula = "=sum(a3:a" & lastrow & ")"
    Range("A" & lastrow + 1).AutoFill _
    Range("a" & lastrow + 1 & ":d" & lastrow + 1)

    End Sub

    --


    Gary


    "Arbin" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I have an excel file where the number of rows can vary. I need to
    > summarize column B, C and D. The numbers starts at row 3 and there can
    > be blank cells in column B, C and/or D where values are missing. In
    > column A there is a text for each row (even those rows without values).
    > To further explain this:
    >
    > Example column A3 to A98 has values, therefore column B, C and D should
    > be summarized with the sum written beneath each row for the columns 3 to
    > 98. In the columns B, C and D there can be randomly empty cells (this
    > should not cause a problem with the sum function)
    >
    > After the summaration of column B, C and D I want to take the
    > summarized value in column D and divide it with the summarized value in
    > column B, the result should be presented on the same row and in column E
    > (in the example the row would be E99)
    >
    > I can get hold of the last row:
    > lastRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    >
    > But I don’t manage to summarize the values in the columns and present
    > the result beneath each row.
    >
    > I hope that my explanation is clear enough
    >
    > /Fredrik
    >
    >
    > --
    > Arbin
    > ------------------------------------------------------------------------
    > Arbin's Profile:
    > http://www.excelforum.com/member.php...o&userid=30542
    > View this thread: http://www.excelforum.com/showthread...hreadid=501953
    >




  4. #4
    Registered User
    Join Date
    01-17-2006
    Posts
    2
    Thank you!

+ 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