Macro to Delete rows containing specific text and one row above

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
i have written code to delete rows containing "Mersand" in Col A from row 2 onwards


I need this amended to delete the row above "Mersand" as well

it would be appreciated if someone would kindly amend my code

Code:
 Sub Del_Mersand()
With Sheets("Imported Data")
Dim LR As Long, i As Long
LR = .Range("A" & .Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If .Range("A" & i).Value Like "*Mersand*" Then Range("A" & i).EntireRow.Delete

Next i
End With
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Changing this line:
VBA Code:
If .Range("A" & i).Value Like "*Mersand*" Then Range("A" & i).EntireRow.Delete
to this:
VBA Code:
If .Range("A" & i).Value Like "*Mersand*" Then .Rows(i-1 & ":" & i).Delete
 
Upvote 0
Solution
Thanks for the help Joe. Code works perfectly
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,251
Members
449,093
Latest member
Vincent Khandagale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top