Code to delete rows after selected cell

proto

New Member
Joined
Jan 2, 2008
Messages
16
I've googled, read, searched forum, and etc. without any luck for what I'm trying to do.

I've got a sheet that I build from a weekly sheet. I can have 30 to 60 rows, but I always have 10 to 20 rows left over with data in column C, none in A, my last code is "Range("A1").End(xlDown).Offset(1, 0).Select" which takes me to the last cell in column A. Does anyone know of a code that I can then delete say 20 rows after that? I tried one code, but it wanted to delete everything below the cell selected which ran & ran.

"-" are blanks. Range moves the selected cell to A4. I want to delete row selected + 19 more.

-|A|B|C|D
1|Y|2|9|J|
2|R|1|8|N|
3|G|4|7|N|
4|-|-|L|-|
5|-|-|L|-|

I know I can do this manually very easily, but why mess with that if I can figure this out? :)

Thanks in advance for any help I may receive!!!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
It does delete 20 rows, but it goes down and then deletes 20 rows back up. So if there are 40 rows, it goes to the bottom and removes rows 40 - 21.
 
Upvote 0
Maybe it should be

Code:
Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(20).EntireRow.Delete
 
Upvote 0
No, still doesn't work. Not sure if it's because Column A has Conditional Formatting or what. I guess this was another reason I was trying to delete from the last row selected and then down.
 
Upvote 0
I suspect that your blank cells aren't actually blank but contain spaces.

Try clicking in the first "blank" cell and running

Code:
ActiveCell.Resize(20).EntireRow.Delete
 
Upvote 0
Still need to test it with more or less data, but here's how I got it to work.

I used your first suggestion:
Range("A1").End(xlDown).Offset(1).Resize(20).EntireRow.Delete
to a new macro button. If I click it once, it'll delete as already stated, but if I click it twice it will delete the remaining cells. I'll play around with it some more.
 
Upvote 0
Now went back and added

Range("A1").End(xlDown).Offset(1).Resize(20).EntireRow.Delete
Range("A1").End(xlDown).Offset(1).Resize(20).EntireRow.Delete

as my last two statements of my original macro and it works. Odd, but it works.

Thanks!!!
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,809
Members
452,944
Latest member
2558216095

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