Define Names / RefersToRange

A

Andre Achtermeier

hi,

i defined a Name "MyName" like

=locACTIVE_Template!$P$49;locACTIVE_Template!$P$86

in VBA i wrote

Dim rng As Range
Set rng = ActiveWorkbook.Names("MyName").RefersToRange

but the code fails and the RefersToRange is nothing.

any idea?
 
J

JE McGimpsey

What do you mean by "the code fails" - do you get a run-time error?
Does the line execute, but no assignment take place?

Is your name defined as a worksheet-level name?
 
T

Tom Ogilvy

I can't reproduce it:

? range("myname").Address(externaL:=True)
[Book1]locACTIVE_Template!$P$49,$P$86
? activeworkbook.Names("MyName").RefersTo
=locACTIVE_Template!$P$49,locACTIVE_Template!$P$86
? activeworkbook.Names("MyName").ReferstoRange.address(external:=True)
[Book1]locACTIVE_Template!$P$49,$P$86

set rng = activeWorkbook.Names("MyName").RefersToRange
? rng.Address(external:=True)
[Book1]locACTIVE_Template!$P$49,$P$86

Go into Insert=>Names and make sure your definition is still good.
 
T

Tom Ogilvy

Note that I used a comma rather than a semicolon, but since you are in
Germany, a semicolon is probably appropriate.
 
A

Andre Achtermeier

hi,

thanx for the fast response.

=locACTIVE_Template!$P$49;locACTIVE_Template!$P$86

is the Range which Excel adds after selecting the cells with
"Insert-Names..."

when i select only 1 cell everything works fine,
but the cells represent 2 different ranges (P49 AND P86)
the code fails, because the Range Object from RefersToRange is NOTHING....
 
T

Tom Ogilvy

Look at my previous response. I can't duplicate that behavior. It works
fine for me.

Try this. With locActive_Template as the active sheet, run this code

set rng = Union(range("P49"),range("P86"))
rng.name = "MyName"

msgbox thisworkbook.Names("MyName").RefersTo

Again, that code works for me.
 

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