Range name as variable: possibe?

KerryFSA

New Member
Joined
Dec 5, 2018
Messages
49
Wrote a long explanation and it didn't post, so simply put: can a range be named using a variable?
e.g. Set Rng = "Range" & N
Then Rng becomes Range1, Range2, etc in a loop.

This works to name sheets as variables ( sh = "Sheet" & M).
Doesn't seem to work with a range name. Get "type mismatch" error.

Thanks.
 
Last edited:

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).
Assuming those are named ranges,

Code:
Set Rng = Range("Range" & N)
 
Upvote 0
Assuming those are named ranges,
Set Rng = Range("Range" & N)

yes Range1, Range2 etc are defined with values.
But the code still hangs up on the Set Rng statement. (1004 - Method 'Range' of object'_Global' failed.)
 
Upvote 0
Dim Range1 as Range, Range2 as range, Rng as Range
Set Range1 = .Range(.Cells(a,b), .Cells(c,d))

etc.
Is this what you mean?
 
Upvote 0
Ah, those are range variables, not range names.

No; VBA lacks reflection (I think that's the relevant attribute) that would enable you to access a variable by cobbling together its name.

There are surely other ways to do whatever it is you're trying to do, but I don't know what that is.
 
Upvote 0
I'm new enough that I don't understand the difference between a range variable and a range name.

There are other ways to deal with the issue; they're just a little less elegant. Thanks very much for your help.
 
Upvote 0
Holler if you need help.
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,289
Members
449,149
Latest member
mwdbActuary

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