I have this code on my VBA to run a loop through my data so I can clean it up to leave just "Y" however i keep getting an error saying invalid next control variable reference. Not sure what to do. Thanks
Dim RowOne As Long
Dim RowTwo As Long
Dim LR As Long
With Sheet1
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
RowOne = .UsedRange.Cells(1).Row
RowTwo = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = lastrow To Firstrow Step -1
'We check the values in the A column in this example
With .Cells(LR, "H")
If Not IsError(.Value) Then
'Delete rows that are not quality checked, this includes "N" and blank, so only keep "Y"
If .Value <> "Y" And .Value <> "Quality" Then .EntireRow.Delete
End If
End With
Next LR
End With
End Sub
Dim RowOne As Long
Dim RowTwo As Long
Dim LR As Long
With Sheet1
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
RowOne = .UsedRange.Cells(1).Row
RowTwo = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = lastrow To Firstrow Step -1
'We check the values in the A column in this example
With .Cells(LR, "H")
If Not IsError(.Value) Then
'Delete rows that are not quality checked, this includes "N" and blank, so only keep "Y"
If .Value <> "Y" And .Value <> "Quality" Then .EntireRow.Delete
End If
End With
Next LR
End With
End Sub