johnsmith5050
New Member
- Joined
- Jun 22, 2014
- Messages
- 8
Hi
I am attempting to use VBA to find a keyword in a column within the active sheet and when it finds this word, to delete the entire row. Once it deletes this row I also need to delete the previous x number of rows, i.e. if keyword is on row 7 and x is 4 it will delete row 7 and the 4 rows prior, so rows 3-6. I have managed to successfully get the first part working as below, it finds the keyword and deletes the row, but I'm not sure what code I need to get it to delete the rows before it. I would really appreciate it if anyone has any suggestions on how to get this working.
I am attempting to use VBA to find a keyword in a column within the active sheet and when it finds this word, to delete the entire row. Once it deletes this row I also need to delete the previous x number of rows, i.e. if keyword is on row 7 and x is 4 it will delete row 7 and the 4 rows prior, so rows 3-6. I have managed to successfully get the first part working as below, it finds the keyword and deletes the row, but I'm not sure what code I need to get it to delete the rows before it. I would really appreciate it if anyone has any suggestions on how to get this working.
Sub DeleteExample()
Dim EX As Long
Application.ScreenUpdating = False
For EX = Range("J" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("J" & EX).Value = "Example" Then
Rows(EX).EntireRow.delete
End If
Next EX
Application.ScreenUpdating = True
End Sub
Last edited: