Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Automating creation of named ranges???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephen - 28 Nov 2007 16:43 GMT
Hi Folks,

I'm have 52 sheets named 1,2,3,etc., that I want to create named ranges on
in the following fashion...

sheet 1 (named "1") has A:C named w1s
sheet 1 (named "1") has D:F named w1c

sheet 2 (named "2") has A:C named w2s
sheet 2 (named "2") has D:F named w2c

... all the way down the line.

Is there a simple way to slap together a one-time use macro so I don't have
t odo this all manually?

Thanks in Advance!
Zone - 28 Nov 2007 17:03 GMT
How about this?  James

Sub NameEm()
   Dim ws As Worksheet
   For Each ws In ThisWorkbook.Worksheets
       ws.Activate
       Columns("A:C").Name = "w" & ws.Name & "s"
       Columns("D:F").Name = "w" & ws.Name & "c"
   Next ws
End Sub

> Hi Folks,
>
[quoted text clipped - 14 lines]
>
> Thanks in Advance!
Peter T - 28 Nov 2007 17:05 GMT
Sub Namer()
Dim b As Boolean
Dim ws As Worksheet
Dim nms As Names
Set nms = ActiveWorkbook.Names
For Each ws In ActiveWorkbook.Worksheets
   With ws
       b = False
       On Error Resume Next
       b = Val(.Name) = .Name
       On Error GoTo 0
       If b Then
           nms.Add "w" & .Name & "s", .Range("A:C")
           nms.Add "w" & .Name & "c", .Range("D:F")
       End If
   End With
Next

End Sub

If you were to use Worksheet level names, also known as Local names, each
sheet could have identically named Names, eg "ws" & "wc"

Regards,
Peter T
> Hi Folks,
>
[quoted text clipped - 13 lines]
>
> Thanks in Advance!
Stephen - 28 Nov 2007 17:16 GMT
that's sweet!

thanks a bunch!

> Sub Namer()
> Dim b As Boolean
[quoted text clipped - 39 lines]
> >
> > Thanks in Advance!
Joel - 28 Nov 2007 17:12 GMT
Sub nameranges()
  For sheetcount = 1 To 52
      refername = "=" & Chr(39) & "names " & sheetcount & Chr(39) & "!A:C"
     ActiveWorkbook.Names.Add Name:="w" & sheetcount & "s", _
        RefersTo:=refername
     refername = "=" & Chr(39) & "names " & sheetcount & Chr(39) & "!D:F"
     ActiveWorkbook.Names.Add Name:="w" & sheetcount & "c", _
        RefersTo:=refername
  Next sheetcount
End Sub

> Hi Folks,
>
[quoted text clipped - 13 lines]
>
> Thanks in Advance!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.