Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Peter Rooney
 
Posts: n/a
Default Identical Name on multiple workbook pages

As a hardened Excel/VBA nut, I'm probably going to be really embarrased when
I get the answer to this, but here goes...

I have a workbook containing a worksheet that records weekly data. I have a
named range ("Data") which I select then clear, via GoTo.
Each week, I copy the latest week's worksheet and create a new worksheet for
the new week. And each week, I select the range "Data" and clear it in the
most recently created worksheet.

the thing is, I always thought that Range names were unique across a
workbook, and that you couldn't have the same Range Name in more than one
worksheet.
Yet each week, I create a new worksheet, GoTo "Data" (which always selects
the correct range in the active worksheet) to create a new template for the
new week.

Excelers, MVPs and the whole of the Western hemisphere will probably be
slapping their heads in disbelief at the dumbness of this question (I have
green ticks for helping people on here, would you believe..?) If I wanted to
refer to "Data" in VBA, I suppose I'd have to qualify it with a worksheet
name.

Can anyone put me straight as to what the rules are?

Thanks (in a terminally bewildered "What's my name again?" sort of way)

Pete


  #2   Report Post  
David Hepner
 
Posts: n/a
Default

Peter,

You are correct that you can have a range "Data" in several worksheets and
since that is possible in order to access those ranges in VBA you will have
to specify which worksheet the range "Data" you are trying to reference.

For example:

Sheets("Sheet1").Application.Goto Reference:="Data"

I hope this answers your question.



"Peter Rooney" wrote:

As a hardened Excel/VBA nut, I'm probably going to be really embarrased when
I get the answer to this, but here goes...

I have a workbook containing a worksheet that records weekly data. I have a
named range ("Data") which I select then clear, via GoTo.
Each week, I copy the latest week's worksheet and create a new worksheet for
the new week. And each week, I select the range "Data" and clear it in the
most recently created worksheet.

the thing is, I always thought that Range names were unique across a
workbook, and that you couldn't have the same Range Name in more than one
worksheet.
Yet each week, I create a new worksheet, GoTo "Data" (which always selects
the correct range in the active worksheet) to create a new template for the
new week.

Excelers, MVPs and the whole of the Western hemisphere will probably be
slapping their heads in disbelief at the dumbness of this question (I have
green ticks for helping people on here, would you believe..?) If I wanted to
refer to "Data" in VBA, I suppose I'd have to qualify it with a worksheet
name.

Can anyone put me straight as to what the rules are?

Thanks (in a terminally bewildered "What's my name again?" sort of way)

Pete


  #3   Report Post  
Peter Rooney
 
Posts: n/a
Default

David,

Thanks for taking the time to answer this question.

At least you didn't laugh...

Pete

"David Hepner" wrote:

Peter,

You are correct that you can have a range "Data" in several worksheets and
since that is possible in order to access those ranges in VBA you will have
to specify which worksheet the range "Data" you are trying to reference.

For example:

Sheets("Sheet1").Application.Goto Reference:="Data"

I hope this answers your question.



"Peter Rooney" wrote:

As a hardened Excel/VBA nut, I'm probably going to be really embarrased when
I get the answer to this, but here goes...

I have a workbook containing a worksheet that records weekly data. I have a
named range ("Data") which I select then clear, via GoTo.
Each week, I copy the latest week's worksheet and create a new worksheet for
the new week. And each week, I select the range "Data" and clear it in the
most recently created worksheet.

the thing is, I always thought that Range names were unique across a
workbook, and that you couldn't have the same Range Name in more than one
worksheet.
Yet each week, I create a new worksheet, GoTo "Data" (which always selects
the correct range in the active worksheet) to create a new template for the
new week.

Excelers, MVPs and the whole of the Western hemisphere will probably be
slapping their heads in disbelief at the dumbness of this question (I have
green ticks for helping people on here, would you believe..?) If I wanted to
refer to "Data" in VBA, I suppose I'd have to qualify it with a worksheet
name.

Can anyone put me straight as to what the rules are?

Thanks (in a terminally bewildered "What's my name again?" sort of way)

Pete


  #4   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Pete,

There are global names, and there are local names.

If you wanted to clear one sheet's "Data" you could use
Worksheets("Sheet Name").Range("Data").ClearContents

To clear all sheets' Data range then use

Sub TryNow()
Dim mysht As Worksheet
For Each mysht In ThisWorkbook.Worksheets
mysht.Range("Data").ClearContents
Next
End Sub


To create a global name, select your range, and type the new name in the name box. To create a
local name, when typing in the name, precede the name by the sheet name, like

SheetName!Data

Or, if your sheet name has a space:
'Sheet Name'!Data

When you press enter, the name will switch to just Data, but it will refer to the local range.

Might I suggest that you get a copy of Jan Karel Pieterse's (with Charles Williams and Matthew
Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

HTH,
Bernie
MS Excel MVP


"Peter Rooney" wrote in message
...
As a hardened Excel/VBA nut, I'm probably going to be really embarrased when
I get the answer to this, but here goes...

I have a workbook containing a worksheet that records weekly data. I have a
named range ("Data") which I select then clear, via GoTo.
Each week, I copy the latest week's worksheet and create a new worksheet for
the new week. And each week, I select the range "Data" and clear it in the
most recently created worksheet.

the thing is, I always thought that Range names were unique across a
workbook, and that you couldn't have the same Range Name in more than one
worksheet.
Yet each week, I create a new worksheet, GoTo "Data" (which always selects
the correct range in the active worksheet) to create a new template for the
new week.

Excelers, MVPs and the whole of the Western hemisphere will probably be
slapping their heads in disbelief at the dumbness of this question (I have
green ticks for helping people on here, would you believe..?) If I wanted to
refer to "Data" in VBA, I suppose I'd have to qualify it with a worksheet
name.

Can anyone put me straight as to what the rules are?

Thanks (in a terminally bewildered "What's my name again?" sort of way)

Pete




  #5   Report Post  
Peter Rooney
 
Posts: n/a
Default

Bernie,

The bit about prefixing the name with the sheetname was VERY helpful.
I already have a copy of the Name Manager, but now it makes a whole lot more
sense.

Thanks for your help :-)

Pete

"Bernie Deitrick" wrote:

Pete,

There are global names, and there are local names.

If you wanted to clear one sheet's "Data" you could use
Worksheets("Sheet Name").Range("Data").ClearContents

To clear all sheets' Data range then use

Sub TryNow()
Dim mysht As Worksheet
For Each mysht In ThisWorkbook.Worksheets
mysht.Range("Data").ClearContents
Next
End Sub


To create a global name, select your range, and type the new name in the name box. To create a
local name, when typing in the name, precede the name by the sheet name, like

SheetName!Data

Or, if your sheet name has a space:
'Sheet Name'!Data

When you press enter, the name will switch to just Data, but it will refer to the local range.

Might I suggest that you get a copy of Jan Karel Pieterse's (with Charles Williams and Matthew
Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

HTH,
Bernie
MS Excel MVP


"Peter Rooney" wrote in message
...
As a hardened Excel/VBA nut, I'm probably going to be really embarrased when
I get the answer to this, but here goes...

I have a workbook containing a worksheet that records weekly data. I have a
named range ("Data") which I select then clear, via GoTo.
Each week, I copy the latest week's worksheet and create a new worksheet for
the new week. And each week, I select the range "Data" and clear it in the
most recently created worksheet.

the thing is, I always thought that Range names were unique across a
workbook, and that you couldn't have the same Range Name in more than one
worksheet.
Yet each week, I create a new worksheet, GoTo "Data" (which always selects
the correct range in the active worksheet) to create a new template for the
new week.

Excelers, MVPs and the whole of the Western hemisphere will probably be
slapping their heads in disbelief at the dumbness of this question (I have
green ticks for helping people on here, would you believe..?) If I wanted to
refer to "Data" in VBA, I suppose I'd have to qualify it with a worksheet
name.

Can anyone put me straight as to what the rules are?

Thanks (in a terminally bewildered "What's my name again?" sort of way)

Pete





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print all charts in a workbook (multiple worksheets) aewsaws Charts and Charting in Excel 4 May 12th 23 03:45 AM
How do I delete the same item from all pages of a workbook? Suz Excel Worksheet Functions 2 August 23rd 05 03:06 PM
Varying page Excel report judypudy Excel Discussion (Misc queries) 6 July 13th 05 08:39 PM
Continuous page numbers in workbook of multiple worksheets Val Excel Discussion (Misc queries) 3 June 23rd 05 07:32 PM
merge/extract data from identical worksheets in a workbook Michelle K Excel Discussion (Misc queries) 5 June 21st 05 05:24 PM


All times are GMT +1. The time now is 02:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"