Hello VBA world,
I wrote a macro to delete code NOT equal to "XXX" in Column F. When I run the for loop, it keeps certain items that should not be kept... in other words, only data rows with symbol XXX should be left but this loop leaves data rows that should be left after the macro has been run and it doesn't delete everything in it should in the range. Another aspect of the code is I don't want it to delete the first row of data, but I want it check and delete (if necessary) all other rows in the data range which is why I used "For x = 2 To finalRow Step 1".
Here's the code. Why isn't it deleting everything in the given range?
Thanks!
I wrote a macro to delete code NOT equal to "XXX" in Column F. When I run the for loop, it keeps certain items that should not be kept... in other words, only data rows with symbol XXX should be left but this loop leaves data rows that should be left after the macro has been run and it doesn't delete everything in it should in the range. Another aspect of the code is I don't want it to delete the first row of data, but I want it check and delete (if necessary) all other rows in the data range which is why I used "For x = 2 To finalRow Step 1".
Here's the code. Why isn't it deleting everything in the given range?
Code:
Dim x As Integer
Dim finalRow As Integer
finalRow = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To finalRow Step 1
If ActiveSheet.Cells(x, 6).Value <> "XXX" Then
ActiveSheet.Cells(x, 6).EntireRow.Delete
End If
Next x
End Sub
Thanks!