Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Worksheet level names

Dear Experts:

this macro, courtesy by Ron Rosenfeld ...

.... searches for the string 'Sales' and creates named ranges for the
respective current regions.

The created named ranges have got a workbook-level scope.

How would I have to re-write the macro to get worksheet level names
(local)? Say, the worksheet on which the ranges have to be named is
named 'Charting'

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


Sub Ranges_Create()
'Courtesy by Ron Rosenfeld, Google Groups
Dim c As Range
Dim firstAddress As String
Dim i As Long
i = 1
With Range("A1")
If .Value = "Sales" Then
.CurrentRegion.Name = "range" & i
firstAddress = .Address
i = i + 1
End If
End With


Set c = Cells.Find(What:="Sales", After:=Range("A1"), _
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)


Do While Not c Is Nothing And c.Address < firstAddress
c.CurrentRegion.Name = "range" & i
i = i + 1
If firstAddress = "" Then firstAddress = c.Address
Set c = Cells.FindNext(c)
Loop

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Worksheet level names

To define a name with local scope it must include the sheetname
(wrapped in single quotes followed by the exclamation character) in its
definition. You can programmatically assign local names as follows:

Range("$A$1").CurrentRegion.Name = "'" _
& ActiveSheet.Name & "'!" & sRngName

So if the sheet was named "Charting" and the value held in sRngName is
"Sales" then the above would read...

Range("$A$1").CurrentRegion.Name = "'Charting'!Sales"

...which is how you would define it in the Namebox or name field in the
Defined Names dialog if you manually selected the area and typed the
name.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Worksheet level names

On Apr 11, 7:56*pm, GS wrote:
To define a name with local scope it must include the sheetname
(wrapped in single quotes followed by the exclamation character) in its
definition. You can programmatically assign local names as follows:

* Range("$A$1").CurrentRegion.Name = "'" _
* * * * * * * * & ActiveSheet.Name & "'!" & sRngName

So if the sheet was named "Charting" and the value held in sRngName is
"Sales" then the above would read...

* Range("$A$1").CurrentRegion.Name = "'Charting'!Sales"

..which is how you would define it in the Namebox or name field in the
Defined Names dialog if you manually selected the area and typed the
name.

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Hi Garry,

thank you very much for your professional help. Regards, Andreas

How come that I am not able anymore to rate the answers. I cannot find
any rating system. Strange, isn't it?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Worksheet level names

AndreasHermle has brought this to us :
How come that I am not able anymore to rate the answers. I cannot find
any rating system. Strange, isn't it?


This forum is no longer supported by Microsoft, thus no way to rate
replies other than to acknowledge the helpfulness to the responders as
you just did here.

Thanks for the feedback; -always appreciated...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Worksheet level names

On Mon, 11 Apr 2011 19:11:44 -0400, GS wrote:

AndreasHermle has brought this to us :
How come that I am not able anymore to rate the answers. I cannot find
any rating system. Strange, isn't it?


This forum is no longer supported by Microsoft, thus no way to rate
replies other than to acknowledge the helpfulness to the responders as
you just did here.

Thanks for the feedback; -always appreciated...


Cool primer on scripted naming of ranges too! Thx!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Worksheet level names

The_Giant_Rat_of_Sumatra brought next idea :
On Mon, 11 Apr 2011 19:11:44 -0400, GS wrote:

AndreasHermle has brought this to us :
How come that I am not able anymore to rate the answers. I cannot find
any rating system. Strange, isn't it?


This forum is no longer supported by Microsoft, thus no way to rate
replies other than to acknowledge the helpfulness to the responders as
you just did here.

Thanks for the feedback; -always appreciated...


Cool primer on scripted naming of ranges too! Thx!


A utility you might find very useful is Jan Karl Peiterse's Name
Manager. You can download it he

http://www.jkp-ads.com/OfficeMarketPlaceNM-EN.asp

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
Change synthax of workbook-level names in one go andreashermle Excel Programming 2 April 19th 10 04:34 PM
Worksheet-level event Exceller Excel Programming 1 September 24th 07 04:44 PM
workbook level name vs worksheet level name clara Excel Programming 1 September 19th 07 02:32 PM
Calling worksheet-level names using insert Autotext in Word NickHK Excel Programming 2 April 3rd 07 02:38 AM
Duplicating worksheet-level names jmg092548 Excel Discussion (Misc queries) 5 August 14th 05 11:11 PM


All times are GMT +1. The time now is 10:37 AM.

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"