Hi there,
The macro given below is one that I got from this forum to delete rows based on the value given in a particular column.
Dim LastRow&, FilterRange As Range
With Sheets("File")
.AutoFilterMode = False
LastRow = .Cells.Find("*", after:=.Range("B1"), searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Set FilterRange = .Range("F1:F" & LastRow)
FilterRange.AutoFilter Field:=1, Criteria1:="=2"
On Error Resume Next
FilterRange.SpecialCells(12).EntireRow.Delete
Err.Clear
.AutoFilterMode = False
End With
Set FilterRange = Nothing
Application.ScreenUpdating = True
It is meant to delete the entire rows (several rows) if the value in Column F in the corresponding row is 2. It works fine and fast. But the first row (first row only), even if the value in Column F is not 2, gets deleted.
I am not at all an expert in making macros. Can anyone help me to get it solved ?
Thanks
The macro given below is one that I got from this forum to delete rows based on the value given in a particular column.
Dim LastRow&, FilterRange As Range
With Sheets("File")
.AutoFilterMode = False
LastRow = .Cells.Find("*", after:=.Range("B1"), searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Set FilterRange = .Range("F1:F" & LastRow)
FilterRange.AutoFilter Field:=1, Criteria1:="=2"
On Error Resume Next
FilterRange.SpecialCells(12).EntireRow.Delete
Err.Clear
.AutoFilterMode = False
End With
Set FilterRange = Nothing
Application.ScreenUpdating = True
It is meant to delete the entire rows (several rows) if the value in Column F in the corresponding row is 2. It works fine and fast. But the first row (first row only), even if the value in Column F is not 2, gets deleted.
I am not at all an expert in making macros. Can anyone help me to get it solved ?
Thanks