Link to home
Start Free TrialLog in
Avatar of SiHodgy007
SiHodgy007Flag for United Kingdom of Great Britain and Northern Ireland

asked on

excel VBA

I'm trying to write a macro with the following logic:

If cell is not empty but cells to right are empty delete line but I seem to have sporadic results.

ISub CleanupChanges()

Dim Cell As Range

With Worksheets("Pack")

LastRow = .Cells(Rows.Count, "B").End(xlUp).Row

    For Each Cell In ActiveWorkbook.Worksheets("Pack").Range("B22:B" & LastRow)
    
           
        If Not IsEmpty(Cell) And IsEmpty(Cell.Offset(0, 1)) And IsEmpty(Cell.Offset(0, 2)) And IsEmpty(Cell.Offset(0, 3)) Then
        
       Cell.EntireRow.Delete
       
       
    End If
        
    Next
           
End With
    
End Sub

Open in new window

SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SiHodgy007

ASKER

Can any one do it cleaner?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, went for

Sub CleanupChanges()
    Dim LastRow As Long
    With Worksheets("Pack")
    LastRow = .Cells(Rows.Count, "B").End(xlUp).row
        For Idx = LastRow To 22 Step -1
        Set Cell = .Range("B" & Idx)
        If Not IsEmpty(Cell) And IsEmpty(Cell.Offset(0, 3)) And IsEmpty(Cell.Offset(0, 4)) And IsEmpty(Cell.Offset(0, 5)) Then
        Cell.EntireRow.Delete
            End If
        Next
    End With
End Sub

Open in new window

Thanks All