VBA Code to delete Rows

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have a spreadsheet that wheneverv the following code appears in column A,
" WSP505 Company No: 10 Date: 10/06/200", 9 rows below and one row above it must be deleted.

The date 10/06/200 will change each month.

I have tried to write code with a wildcard character i.e. where " WSP505" occurs and anything after this code 9 rows below and one row above must be deleted.


See my code
nisswip.xls
ABCDEF
54WSP505CompanyNo:10Date:10/06/200
Sheet1


I have attached sample data below

It would be appreciated if anyone could assist me

Thanks

Howard
nisswip.xls
ABCDEF
54WSP505CompanyNo:10Date:10/06/200
Sheet1
 
I asked that in my first post

So to be clear, we're looking for the first 6 characters in column A to be WSP505. And when found (in your example it's in row 54)...So
rows 55,56,57,58,59,60,61,62,63 And 53 Should be deleted, right ?

You said that was correct...

but anyway...

Replace these 2 lines

Range(i + 1 & ":" & i + 9).EntireRow.Delete
Rows(i - 1).Delete

With this 1 line

Range(i - 1 & ":" & i + 9).EntireRow.Delete

That should do it.
 
Upvote 0

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.
Hi Jonmo1

Thanks for the help, much appreciated

Regards

Howard
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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