if word found delete 3 rows from another column

diimoo1

New Member
Joined
Jun 12, 2011
Messages
34
Hi - Would like to get your help below if possible.

I have data that look like


Column1Column2
speedXXX
Other Value
Other Value
Other Value
Other Value
Speed
Other Value
Other Value
Other ValueXXX
Other Value
Other Value
Other Value
speed
Other Value
Other Value
Other Value
Other valueXXX

desired result:



Column1Column2
speedXXX
Other Value
Other Value
Other Value
Other Value
SpeedXXX
Other Value
Other Value
Other Value
Other Value
Other Value
Other Value
speedXXX
Other Value
Other Value
Other Value
Other value




I tried the below code - but no luck


VBA Code:
Sub DeleteRow()
  Dim R As Range, cellsToDel As String
  'looking for cells that contain the word 'speed'
  Set R = ActiveSheet.Range("A:A").Find("speed", LookIn:=xlValues)
  'if found
  Do While Not R Is Nothing
    'get cells address to be deleted
    cellsToDel = "B" & R.Row - 3 & ":A" & R.Row + 0
    'delete the cells
    ActiveSheet.Range(cellsToDel).Delete xlShiftUp
    'looking for cells that contain the word 'bottom' again
    Set R = ActiveSheet.Range("A:A").Find("speed", LookIn:=xlValues)
  Loop
End Sub


thanks in advance
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Please tell me in words what you want.
So if some value is in Column 1 do this.
Do not ask me to read your script
 
Upvote 0
Yes definitely - If column A contains or found " Speeed" then delete 3 cells up in Column B's next non-empty cell ( i.e XXX)
Basically, delete the 3 rows before "XXX" - and do next "XX" until the last "speed" found in column A

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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