Hello,
I'm using the below code but it does not seem to work, can someone please help me correcting this?
I am trying to delete any row in sheet 'Temp' when the date in column AM does not equal the specific date in sheet 'Home' cell C4.
Thanks in advance.
I'm using the below code but it does not seem to work, can someone please help me correcting this?
I am trying to delete any row in sheet 'Temp' when the date in column AM does not equal the specific date in sheet 'Home' cell C4.
Thanks in advance.
VBA Code:
'Delete row if date in column AM in 'Temp' does NOT equal date in 'Home' C4
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
Sheets("Temp").Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "AM")
If Not IsError(.Value) Then
If .Value <> Sheets("Home").Range("C4") Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With