Delete two rows between a named range

shanecb

New Member
Joined
Dec 4, 2013
Messages
3
Please can someone assist me in trying to delete two rows in between a named range (not including the named ranges)? I currently have:

Sub ClearDMM()
Rows(Range("DMMCI").Row + 1 & ":" & (Range("DMMCI2").Row - 1)).Delete
End Sub


The problem is if the macro / button is run twice then as you'll see above ("DMMCI2").Row + 1 is the row above ("DMMCI").Row - 1 and therefore gets deleted.

Is there a better way to only delete rows in between a named range if the upper and lower row are not next to eachother? Or a totally different way?

Many thanks for your help,
Shane
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
See if this does what you want:
Code:
Sub ClearDMM()
Select Case Range("DMMCI").Row - Range("DMMCI2").Row
    Case Is > 1
    Rows(Range("DMMCI2").Row + 1 & ":" & (Range("DMMCI").Row - 1)).Delete
    Case Is < -1
    Rows(Range("DMMCI").Row + 1 & ":" & (Range("DMMCI2").Row - 1)).Delete
End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,459
Messages
6,130,758
Members
449,588
Latest member
accountant606

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