Prevent Named Range Reference From Changing

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have two named ranges I use as sources for their respective combobox lists.
Since the ranges are dynamic, I use a formula as reference ...

Rich (BB code):
=OFFSET(ROSTER!$A$2,0,0,COUNTA(ROSTER!$E:$E)-2,1)

WHat is happening though, from within my VBA application, the worksheet will many times get altered with the deletion and/or addition of rows, and the first parameter of OFFSET will change. When it changes, my list source is off.

For example,if I delete a row, the $A$2 will change to $A$3. If I delete another row, it changes to $A$4. When this happens my list source misses the first two values of the column, and makes up for the difference with empty spaces.

How can I prevent the involuntary changing of this parameter?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Thank you Jim!

I substituted my original with the INDIRECT function,

Named range 'employeenumber' refers to:
Rich (BB code):
=OFFSET(INDIRECT(ROSTER!$A$2),0,0,COUNTA(ROSTER!$A:$A)-2,1)

but now I get an error ("Method 'Range' of object '_Worksheet' failed" with this line in my code.

Rich (BB code):
    With ws_rstr
        lrow = (.Cells(.Rows.Count, "A").End(xlUp).Row) - 1
        .Range("A2:U" & lrow).Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlNo
     End With
    Me.empl_no.Clear
    For Each cl In ws_rstr.Range("employeenumber")
        If cl.Value <> 0 Then
            Me.empl_no.AddItem cl.Value
        End If
    Next cl
    Me.empl_no.AddItem "NEW"

Any help would be greatly appreciated!
 
Last edited:
Upvote 0
Just curious but why, In the 2 lines of code you have shown are you in the first using the "-2" and in the second using the "-1"?
In each case you are EXCLUDING the last row in your range. Is that what you want?

Rich (BB code):
=OFFSET(ROSTER!$A$2,0,0,COUNTA(ROSTER!$E:$E)
Rich (BB code):
-2,1)

lrow = (.Cells(.Rows.Count, "A").End(xlUp).Row) - 1lrow = (.Cells(.Rows.Count, "A").End(xlUp).Row) - 1
 
Upvote 0
Try this... (in RefersTo Box for "employeenumber")
Should Prevent your reference to $A$2 from EVER CHANGING!!

=OFFSET(INDIRECT("'ROSTER'!$A$2"),0,0,COUNTA(INDIRECT("'ROSTER'!$E:$E"))-1,1)
 
Upvote 0
Thanks Jim for your support. This seems to be working wonderfully.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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