Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to delete rows with 1 in column B

    I need a macro to delete the entire row where there is a 1 in column B. Also, to delete one row above. So where there is a 1 in column B, I need that row deleted and the one above. Any help is greatly appreaciated.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Linda,

    This should do the trick:
    Code:
    Option Explicit
    
    Sub MyDelete()
    
       Dim lLastRow As Long
       Dim lCurRow As Long
       Dim zRowRng As String
       
       Application.ScreenUpdating = False
       
       lLastRow = Cells(Rows.Count, "B").End(xlUp).Row
       Cells(lLastRow, 2).Select
         
       Do While ActiveCell.Row() >= 2
       
         If ActiveCell.Value = 1 Then
           lCurRow = ActiveCell.Row()
           zRowRng = Format(lCurRow - 1) & ":" & Format(lCurRow)
           Rows(zRowRng).EntireRow.Delete
         End If
       
         ActiveCell.Offset(-1, 0).Select
        
       Loop
    
       If ActiveCell.Value = 1 Then ActiveCell.EntireRow.Delete
       
    End Sub

    MyDeleteStartData.PNGMyDeleteResults.PNG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you so much. Saved me hours of work.

Posting Permissions

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