Named ranges - references changing

joey peanuts

New Member
Joined
Mar 20, 2011
Messages
18
This code is changing the scope of my named ranges. On this worksheet, I want on the ranges to go from $A$9:$A$60 as an example. When this code runs, the .cut part of it is reducing the height of the ranges each time through.

HTML:
'if there are empty rows, move all the rows up to fill them
Dim isEMPTY As Boolean, startempty As String
isEMPTY = False
For Each cell In Worksheets("RBA_RECT").Range("A9:A60").Cells
    If cell.Value = "" Then
        'only need to know where the empty block starts
        If isEMPTY = False Then
            startempty = cell.Address
            isEMPTY = True
        End If
    Else
        'only make changes if we are now on a row that has data and we previously found an empty cell
        If startempty <> "" Then
            Range(cell.Address, "DA60").Cut Range(startempty)
            'reset startempty for the next one
            startempty = ""
        End If
    End If
Next cell

Is there a way to keep this from happening or to redefine the range scopes?

Thank you
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
One possible solution could be to define the named range using the INDIRECT function. Then its scope wouldn't be affected when you delete rows.

Example Named Range "Refers to" formula
=INDIRECT("Sheet1!A9:A60")
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,943
Latest member
Newbie4296

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