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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,309
Office Version
  1. 365
Platform
  1. Windows
Katie

Have you already recorded this?

If so can you post the code, and tell us what help you need to alter it.
 

katie1071

Board Regular
Joined
Mar 17, 2003
Messages
120
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,309
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,144,694
Messages
5,725,803
Members
422,640
Latest member
KazPL

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
Top