Del blank but skip if value is in cell G

  • I am trying to make this macro delete blank rows and skip any rows that has subtotal in the line.



    Sub Delrow()
    Dim lr As Long
    lr = Range("c" & Rows.Count).End(xlUp).Row
    Dim i As Long
    For i = lr To 2 Step -1 'loops from last row to row 2
    If Value("G") = "subtotals" Then Skip 'This like is the code that is supposed to skip
    If Range("c" & i) = "" Then Range("c" & i).EntireRow.Delete
    Next i
    End sub

  • The example data is only a partial example but I expect this will fill your need. Let me know if it doesn't.


    Code
    Sub Delrow()
        Dim N As Long, i As Long
        N = Cells(Rows.Count, "K").End(xlUp).Row 'Count column K to determine range.
        'Using K because it appears to always have a value if the line is used for anything
        For i = N To 1 Step -1 
            If Cells(i, "C") < 1 And Cells(i, "G") < 1 Then
                Cells(i, "C").EntireRow.Delete 
            End If
        Next i
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!