Using the range object (Error 424)

RobH1979

New Member
Joined
Mar 9, 2009
Messages
9
I have a combo box whose source is a named range ("variablelist"). However I need to update the named range every time new data is input into the spreadsheet.

I have therefore written the following code to update the named range. However when I run it I get 'ERROR 424 - Object Required 'on the SET statement. I have MS DAO 3.6 Object Library referenced. Does anyone know what is causing this error?

Dim rngVariable As Range
Dim strSet as String

strset = "Settings"

Sheets(strSet).Select
Range("A2").Select

Set rngVariable = Range(Selection, Selection.End(xlDown)).Select

ActiveWorkbook.Names.Add Name:="VariableList", RefersTo:=rngVariable
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Remove the .Select from the end of that line.
 
Upvote 0
Hi,

Remove the select method from this line:
Rich (BB code):
Set rngVariable = Range(Selection, Selection.End(xlDown)) .Select

When we are working with ranges from VBA it is very rare that we actually need to select them. In fact, selecting ranges can cause problems and slow the code down, so we try to avoid selecting when we can! This code should produce the same result without selecting:

Rich (BB code):
Sub test()
    Dim rngVariable As Range
 
    With Sheets("Settings")
        Set rngVariable = .Range("A2", .Range("A2").End(xlDown))
    End With
 
    ThisWorkbook.Names.Add Name:="VariableList", RefersTo:=rngVariable
End Sub

Hope that helps
 
Upvote 0
Or even:
Code:
Sub test()
    With Sheets("Settings")
        .Range("A2", .Range("A2").End(xlDown)).Name = "VariableList"
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

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