Need help with simple VB code

katie1071

Board Regular
Joined
Mar 17, 2003
Messages
120
Hi,

I am not a programmer but can typically get through a simple macro by recording in excel and then editing in VB but can't seem to get this one.

I need to do the following:
-find a cell with specific text, which I've got
-select the active row and delete the row and the 3 rows below it

Hope that makes sense!

Thanks
Katie
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Katie

Have you already recorded this?

If so can you post the code, and tell us what help you need to alter it.
 
Upvote 0
Here is a quick and dirty example. Once I find the text, I want to delete the row the text is found in and the 3 rows below it. With this macro, it specifies rows "2:5" and the rows I want to delete will never be in the same rows. It will vary...

Cells.Find(What:="Internal Data", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Rows("2:5").Select
Selection.Delete Shift:=xlUp
 
Upvote 0
Katie

Untested but perhaps something like this.
Code:
Set rngFound = Cells.Find(What:="Internal Data", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
If Not (rngFound Is Nothing) Then
      rngFound.EntireRow.Resize(3).Delete Shift:=xlUp
End If
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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