Consulting

Results 1 to 6 of 6

Thread: Sum Cell Values Until Blank Cells With VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Unhappy Sum Cell Values Until Blank Cells With VBA

    I found this code on the internet. How do I get the sum value to appear in the empty cell above the cells containing consecutive values. I'm thinking of running the code from the last row. Thank for your help


    https://www.extendoffice.com/documen...til-blank.html

    Sub InsertTotals()
    'Updateby Extendoffice
        Dim xRg As Range
        Dim i, j, StartRow, StartCol As Integer
        Dim xTxt As String
        On Error Resume Next
        xTxt = ActiveWindow.RangeSelection.AddressLocal
        Set xRg = Application.InputBox("please select the cells:", "Kutools for Excel", xTxt, , , , , 8)
        If xRg Is Nothing Then Exit Sub
        StartRow = xRg.Row
        StartCol = xRg.Column
        For i = StartCol To xRg.Columns.Count + StartCol - 1
            For j = xRg.Row To xRg.Rows.Count + StartRow - 1
                If Cells(j, i) = "" Then
                    Cells(j, i).Formula = "=SUM(" & Cells(StartRow, i).Address & ":" & Cells(j - 1, i).Address & ")"
                    StartRow = j + 1
                End If
            Next
            StartRow = xRg.Row
        Next
    End Sub
    Last edited by Aussiebear; 10-01-2021 at 12:39 PM. Reason: Added code tags to supplied code

Posting Permissions

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