View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NateBuckley NateBuckley is offline
external usenet poster
 
Posts: 146
Default Scope of range names

If I understand your question correctly I think you are talking about global
and local variables.

If you have the code in "ThisWorkBook

Public myRange as Range

Private Sub Workbook_Open()
myRange = Sheets("Sheet1").Range("A1:A5")
myRange.name = "Doodle"
End Sub

Then You create a global variable called myRange which is a Range Object.
The workbook opens and assigns this object (myRange) to the cells Sheet1 a1
to a5. This range is available to other sheets to use and I think also to
modules. So you can display it in a message box by using the line
msgBox( ThisWorkBook.myRange.name).

"Otto Moehrbach" wrote:

Excel XP & Win Vista
I need some help on something rather basic and I'm embarrassed to ask. When
I MANUALLY assign a range name to a range, what must I do for the scope of
the range name to be the workbook? Same question for the scope to be the
sheet.
When I assign a range name via VBA, same 2 questions. For example:
Rng.Name="Doodle" 'Is the scope workbook or sheet?
Range("A1").Name="Doodle" 'Is the scope workbook or sheet?
With Sheet("TheSheet")
.Range("A1").Name="Doodle"
End With 'Is the scope workbook or sheet?

One more question: What/Where do I look at the range names in a workbook to
determine the scope of a range name? What do I look for? Thanks for your
time and I won't show my face for a while. Otto