none
Macro to delete all rows below a specific row RRS feed

  • Question

  • Hi,

    I am struggling with deleting all rows below a specific row. The first row that has“Ref” in Col “D” and an empty cell in Col “F”, I need to delete all rows starting from this row to Last row.

    Thanks


    • Edited by D.Hanna Thursday, May 18, 2017 6:46 PM
    Thursday, May 18, 2017 6:32 PM

All replies

  • Sub TestMacro()
        Dim rngC As Range
        
        If Application.CountIfs(Range("D:D"), "Ref", Range("F:F"), "") = 0 Then
            MsgBox """Ref"" in D and blank in F not found."
            Exit Sub
        End If
        
        Set rngC = Range("D:D").Find("Ref")
        
        While Not rngC Is Nothing
            If rngC.Offset(0, 2).Value = "" Then
                Range(rngC, Cells(Rows.Count, 1)).EntireRow.Delete
                Exit Sub
            End If
            Set rngC = Range("D:D").FindNext(rngC)
        Wend
    End Sub
    Tuesday, May 23, 2017 5:03 PM