Code error

hallingh

Well-known Member
Joined
Sep 11, 2010
Messages
769
I'm trying to set a current named range in my sheet equal to a dimmed range in my macro code. I'm getting a Subscript out of range error, so I know my coding is off. This is what I have:

Code:
Public Sub FilterLists_Click()
Dim oRange1 As Range
Dim RangeNum As Long

RangeNum = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row

oRange1 = Sheets("Sheets1").Range("A1:A" & RangeNum)
Range("ListName") = oRange1

End Sub

Any help with this would be greatly appreciated. Thanks!

Hank
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Something like this...

Code:
Public Sub FilterLists_Click()
Dim RangeNum As Long

RangeNum = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row

ActiveWorkbook.Names.Add Name:="ListName", RefersTo:=Sheets("Sheet1").Range("A1:A" & RangeNum)

End Sub
 
Upvote 0
The reason I wasn't adding a new named range is because I already have a named range called "ListName." Is is not possible to just change the range of ListName?

Thanks a lot for the help.

Hank
 
Upvote 0
The reason I wasn't adding a new named range is because I already have a named range called "ListName." Is is not possible to just change the range of ListName?

Thanks a lot for the help.

Hank

The code I posted will overwrite the existing range which in effect is what you're asking for.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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