Retrieving range string from named range

C

clapper

I have an input box that defines a range, which is then named, i.e. myRange.

Later in the program, I have need of the String version of the range that
the user entered.

To be specific, the following line of code DOES work:

Sheets(i).Range("k26:k48").Value = Sheets(1).Range("k26:k48").Value

However, the same line, using the SAME range, just in a named format, does
NOT work:

Sheets(i).Range("myRange").Value = Sheets(1).Range("myRange").Value

Does this make sense?
 
T

Tom Ogilvy

If myrange is truly a range found in the listing in Insert=>Names=>Define

then
Dim rng as Range
set rng = Sheets(1).Range("MyRange")
Sheets(i).Range(rng.Address).Value = rng.Value

or

With Sheets(1).Range("MyRange")
Sheets(i).Range(.Address).Value = .Value
End With
 
C

clapper

Tom,

No, the range is not found in 'Names'->'Define'. The sheet is protected, so
all of that is greyed out.

Maybe I'm calling it the wrong thing. What I'm calling a 'named range' is
being created in the macro with the following code:

Dim ItemRange As Range
Set ItemRange = Application.InputBox(prompt:="Select Range of Items...",
Type:=8)

Does that shed any light on the issue?
 
T

Tom Ogilvy

Yes, you have a variable of type Range which is referencing a specific set
of cells in a specific worksheet. So to use that:

Sheets(i).Range(ItemRange.Address).Value = ItemRange.Value
 
C

clapper

That did it. Thanks!

Tom Ogilvy said:
Yes, you have a variable of type Range which is referencing a specific set
of cells in a specific worksheet. So to use that:

Sheets(i).Range(ItemRange.Address).Value = ItemRange.Value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top