Hi all,
I have the following macro, which deletes any row not equalling the word “Apple” in column D.
However, I wish it to only commence from row 5 of the data in the tab, instead of deleting the top 4 rows (which are headings) as it currently does. The end point is variable, so it could be row 10, or row 60.
Can anyone help with this, please?
Thanks,
Rich
I have the following macro, which deletes any row not equalling the word “Apple” in column D.
However, I wish it to only commence from row 5 of the data in the tab, instead of deleting the top 4 rows (which are headings) as it currently does. The end point is variable, so it could be row 10, or row 60.
Can anyone help with this, please?
VBA Code:
Sub FilterForCRS()
Dim Firstrow As Long
Dim lastRow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With Sheets("CPSPG")
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = .UsedRange.Cells(1).Row
lastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = lastRow To Firstrow Step -1
With .Cells(Lrow, "D")
If Not IsError(.Value) Then
If .Value <> "APPLE" Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Thanks,
Rich
Last edited by a moderator: