garypea123
Board Regular
- Joined
- Mar 16, 2020
- Messages
- 221
- Office Version
- 365
- Platform
- Windows
Good MOrning,
Me again - I would like to try and tidy up a VBA to get everything on one command.
Below, the list seems to increase and increase, but I would prefer to add the criteria to one line, as opposed to keep adding a loop.
I did try to do do the below. But it seems to delete rows which I would not expect it to delete so I think that there is something not right.
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Gary*" or Like "John* Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Existing VBA:
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Gary*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Tom*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "John*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Keith*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Me again - I would like to try and tidy up a VBA to get everything on one command.
Below, the list seems to increase and increase, but I would prefer to add the criteria to one line, as opposed to keep adding a loop.
I did try to do do the below. But it seems to delete rows which I would not expect it to delete so I think that there is something not right.
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Gary*" or Like "John* Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Existing VBA:
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Gary*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Tom*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "John*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i
Last = Cells(Rows.Count, "B").End(xlUp).Row
For i = Last To 6 Step -1
If Cells(i, 2) Like "Keith*" Then
Cells(i, 2).EntireRow.Delete
End If
Next i