PC Review


Reply
Thread Tools Rate Thread

How Can I Loop through all the range names in a workbook in VBA?

 
 
Kay
Guest
Posts: n/a
 
      9th Nov 2007
Hi, I am using Excel2002 SP3
I need to identify all the range names within a workbook

Any ideas? My below code does not work error message 'argument not
optional'

Dim ws As Worksheet
Dim rng As Range

For Each ws In ActiveWorkbook.Worksheets
For Each rng In ws.Range
Select Case rng.Name
Case "rangename"
do soemthing
Case Else
End Select
Next
Next

 
Reply With Quote
 
 
 
 
Darren Hill
Guest
Posts: n/a
 
      9th Nov 2007
Try this:
Sub IterateNames()
Dim ws As Worksheet
Dim nm As Name
For Each ws In ActiveWorkbook.Worksheets
For Each nm In ws.Names
Select Case nm.Name

Case "rangename"
'do soemthing
Case Else
Debug.Print nm.Name
End Select
Next
Next
End Sub

Darren
Kay wrote:
> Hi, I am using Excel2002 SP3
> I need to identify all the range names within a workbook
>
> Any ideas? My below code does not work error message 'argument not
> optional'
>
> Dim ws As Worksheet
> Dim rng As Range
>
> For Each ws In ActiveWorkbook.Worksheets
> For Each rng In ws.Range
> Select Case rng.Name
> Case "rangename"
> do soemthing
> Case Else
> End Select
> Next
> Next
>

 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      9th Nov 2007
Sub name_it()
Dim n As Name
Dim r As Range
Dim s As String
For Each n In ThisWorkbook.Names
MsgBox (n.Name)
s = Range(n).Address
MsgBox (s)
Next n
End Sub


--
Gary''s Student - gsnu2007a


"Kay" wrote:

> Hi, I am using Excel2002 SP3
> I need to identify all the range names within a workbook
>
> Any ideas? My below code does not work error message 'argument not
> optional'
>
> Dim ws As Worksheet
> Dim rng As Range
>
> For Each ws In ActiveWorkbook.Worksheets
> For Each rng In ws.Range
> Select Case rng.Name
> Case "rangename"
> do soemthing
> Case Else
> End Select
> Next
> Next
>
>

 
Reply With Quote
 
=?Utf-8?B?RHVrZSBDYXJleQ==?=
Guest
Posts: n/a
 
      9th Nov 2007
Have you tried Insert->Names->paste list? BE SURE TO SELECT A LARGE RANGE
OF EMPTY CELLS FIRST

"Darren Hill" wrote:

> Try this:
> Sub IterateNames()
> Dim ws As Worksheet
> Dim nm As Name
> For Each ws In ActiveWorkbook.Worksheets
> For Each nm In ws.Names
> Select Case nm.Name
>
> Case "rangename"
> 'do soemthing
> Case Else
> Debug.Print nm.Name
> End Select
> Next
> Next
> End Sub
>
> Darren
> Kay wrote:
> > Hi, I am using Excel2002 SP3
> > I need to identify all the range names within a workbook
> >
> > Any ideas? My below code does not work error message 'argument not
> > optional'
> >
> > Dim ws As Worksheet
> > Dim rng As Range
> >
> > For Each ws In ActiveWorkbook.Worksheets
> > For Each rng In ws.Range
> > Select Case rng.Name
> > Case "rangename"
> > do soemthing
> > Case Else
> > End Select
> > Next
> > Next
> >

>

 
Reply With Quote
 
Kay
Guest
Posts: n/a
 
      9th Nov 2007
Thanks Guys

Both worked - should have been looking at Name rather than Range

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range Defined names loop mp Microsoft Excel Programming 5 23rd Sep 2009 05:11 PM
how to make range names universal in workbook april Microsoft Excel Misc 3 8th Jun 2009 08:33 PM
Macro in one workbook that names a range in a different workbook Tony Bender Microsoft Excel Programming 2 6th Mar 2009 12:27 AM
Copying Range Names to another open workbook ll Microsoft Excel Programming 4 27th Apr 2007 09:54 PM
copy a sheet not all the range names in a workbook JulieD Microsoft Excel Misc 2 12th Oct 2004 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:03 PM.