MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Macro: Delete a range of rows based on changing variables

Posted by Russell F. Bryant on November 01, 2001 11:49 AM

I need to create a macro that will delete from row x to row y. Row x is determined by the formula =Row(rangename1) and Row y is determined by the formula =Row(RangeName2).

Posted by Todd on November 01, 2001 12:03 PM

Try something like this:

Dim i as integer
For i = 1 to (y-x)
next i

You might have to tweak it a little.

Posted by Russ on November 01, 2001 1:41 PM

Thanks Todd. I could not get it to work. I'm trying to delete rows 25 to 29. Next time it might be rows 30 to 40. I have two cells B2 and B3 that indicate the rows to delete. Can you provide any additional help?
I have some reference books at home that I will bring to work in the morning.

Posted by Lantos on November 01, 2001 2:32 PM

Rows([B2] & ":" & [B3]).Delete

Posted by Russ on November 02, 2001 7:48 AM

Thank you Todd and Lantos - Task Completed