All of my data is in the "D" column.
I want to start a specific cell (ie. D249) and then select the next 600 and delete them (ie. D250-D850). Then I want to skip the next one down (ie. D851) and delete the next 600 below that. I want to do this until it gets to the end, which is like D19000. I think I need to use a while loop to check if data is present in the cell I'm looking at.
This is the code I have so far:
Sub delete600rows()
'delete600rows Macro
'Keyboard Shortcut: Ctrl+a
ActiveSheet.Range("D249").Select
While LEN()>0
Range("D249:D848").Select
Selection.Delete Shift:=xlUp
End Sub
How do I write the condition for the while loop and how do I make the range select work the way I want it to?
The one below should work. I have not tested it extensively. I put an option where you can select the cell you want to start from and how many rows you want to delete. If those are standard just hard code them in the code :)
You count use a for loop and add instance of 501, the cyntax is off, but I grew up in php
This is more of an idea for you to adapt than the correct code:
Something like this could work as you always delete 600 Rows at a time then you want to keep the next. So after you have deleted the range 250-850 the row 250 is now containing what was in row 851 before deleting it.
try this code:
If you want to delete Entire Row replace
Rng.Delete xlUp
withRng.EntireRow.Delete
.(sorry, commenting not yet possible for me.)
I'm a little confused I have to say: Why would you only want to delete 600 rows if you can just delete everything from cell D249 downwards? Is there something you are looking for in this column? What is the use of this?
Otherwise there would be a possibility to check for the last row:
And then you could just delete everything from D249 to the last filled row in your workbook.
If I am wrong, there would really be some more clarification neccessairy.