![]() |
Code deletes first row/headers.
Code works, but keeps deleting the headers in row 1. How to avoid/fix
please? Sub Delete_ROUTES_ColE() Application.ScreenUpdating = False Dim Firstrow As Long Dim Lastrow As Long Dim Lrow As Long With ActiveSheet 'Set the first and last row to loop through Firstrow = .UsedRange.Cells(2).Row 'The 1 represents the RowIndex Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row 'Loop from Lastrow to Firstrow (bottom to top) For Lrow = Lastrow To Firstrow Step -1 'Check the values in the D column With .Cells(Lrow, "E") If .Value < "APPLES" And .Value < "GRAPES" And .Value < "PLUMS" And .Value < "DATES" And .Value < "PEARS" Then .EntireRow.Delete End With Next Lrow End With Application.ScreenUpdating = True End Sub |
Code deletes first row/headers.
On Oct 8, 10:51*am, "J.W. Aldridge"
wrote: Code works, but keeps deleting the headers in row 1. How to avoid/fix please? Sub Delete_ROUTES_ColE() Application.ScreenUpdating = False * * * * Dim Firstrow As Long * * * * Dim Lastrow As Long * * * * Dim Lrow As Long * * * * With ActiveSheet * * * * 'Set the first and last row to loop through * * * * Firstrow = .UsedRange.Cells(2).Row 'The 1 represents the RowIndex * * * * Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row * * * * 'Loop from Lastrow to Firstrow (bottom to top) * * * * For Lrow = Lastrow To Firstrow Step -1 * * * * 'Check the values in the D column * * * * With .Cells(Lrow, "E") * * * * * * If .Value < "APPLES" And .Value < "GRAPES" And ..Value < "PLUMS" And .Value < "DATES" And .Value < "PEARS" Then .EntireRow.Delete * * * * End With * * * * Next Lrow * * End With Application.ScreenUpdating = True End Sub I would have done it differently but instead of cells(2), use cells(2,1) or range("a2") |
All times are GMT +1. The time now is 07:21 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com