Finding and deleting "Total" row RRS feed

  • Question

  • I have a peculiar situation in excel VBA code. I have a total row in excel sheet. However, it neither says the word "total" nor does the cell has any formula. There are 10 "total" cells, one for each column. I need to loop through the column and find the total cell (by checking if the value for each cell matches the sum of previous cells and then delete that row. All the "total" cells are in the same row. any help please?
    Friday, April 15, 2016 1:40 PM

All replies

  • If column B is one of the columns, with numbers starting in row 2:

    Sub TestMacro()
        Dim lRow As Long
        For lRow = 3 To Cells(Rows.Count, "B").End(xlUp).Row - 1
            If Application.Sum(Range("B2:B" & lRow)) = Cells(lRow + 1, "B").Value Then
                Cells(lRow + 1, "B").EntireRow.Delete
                Exit Sub
            End If
        Next lRow
    End Sub

    • Proposed as answer by ryguy72 Saturday, April 16, 2016 1:26 PM
    Friday, April 15, 2016 6:57 PM