PC Review


Reply
Thread Tools Rate Thread

Convert Worksheet List to Named Array Constant

 
 
Steph
Guest
Posts: n/a
 
      11th Apr 2009
I have a list on a worksheet. I would like to convert that list to a named
range. Is there a VBA procedure that would do so?

For example, in cells A1:A3 I have

A1 -> Jan
A2 -> Feb
A3 -> Mar

I would like to convert this list to a defined name called "Months". The
defined name dialog box "refers to" input for the name "Months" would look
like:

={"Jan","Feb","Mar"}

Thanks for your help.

--
Steph
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      11th Apr 2009
I think this does what you want...

Sub CreateNameArray()
Dim X As Long
Dim R As Range
Dim N As String
Set R = Worksheets("Sheet4").Range("A1:A3")
N = "={"
For X = 1 To R.Count
N = N & """" & R(X).Value & ""","
Next
N = Left(N, Len(N) - 1) & "}"
Names.Add Name:="Months", RefersTo:=N
End Sub

--
Rick (MVP - Excel)


"Steph" <(E-Mail Removed)> wrote in message
news:25BE7CDF-4005-4ECA-B689-(E-Mail Removed)...
>I have a list on a worksheet. I would like to convert that list to a named
> range. Is there a VBA procedure that would do so?
>
> For example, in cells A1:A3 I have
>
> A1 -> Jan
> A2 -> Feb
> A3 -> Mar
>
> I would like to convert this list to a defined name called "Months". The
> defined name dialog box "refers to" input for the name "Months" would look
> like:
>
> ={"Jan","Feb","Mar"}
>
> Thanks for your help.
>
> --
> Steph


 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      11th Apr 2009
You actually don't need a VBA procedure to define a named range. You can
just select the range and define the name attached to it. If the range is
varying in size over time, you can define a dynamic range. When you
reference it, do something like this

Dim myRange as Excel.Range
Dim myWS as Excel.worksheet

Set myWS = Worksheets("Sheet1") 'or whatever sheet it's on
Set myRange = myws.Range("Months")


"Steph" wrote:

> I have a list on a worksheet. I would like to convert that list to a named
> range. Is there a VBA procedure that would do so?
>
> For example, in cells A1:A3 I have
>
> A1 -> Jan
> A2 -> Feb
> A3 -> Mar
>
> I would like to convert this list to a defined name called "Months". The
> defined name dialog box "refers to" input for the name "Months" would look
> like:
>
> ={"Jan","Feb","Mar"}
>
> Thanks for your help.
>
> --
> Steph

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      11th Apr 2009
???

range("a1:a12").name="Months"

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Steph" <(E-Mail Removed)> wrote in message
news:25BE7CDF-4005-4ECA-B689-(E-Mail Removed)...
>I have a list on a worksheet. I would like to convert that list to a named
> range. Is there a VBA procedure that would do so?
>
> For example, in cells A1:A3 I have
>
> A1 -> Jan
> A2 -> Feb
> A3 -> Mar
>
> I would like to convert this list to a defined name called "Months". The
> defined name dialog box "refers to" input for the name "Months" would look
> like:
>
> ={"Jan","Feb","Mar"}
>
> Thanks for your help.
>
> --
> Steph


 
Reply With Quote
 
Steph
Guest
Posts: n/a
 
      11th Apr 2009
Rick,

Thank you. That's exactly what I was looking for.

--
Steph


"Rick Rothstein" wrote:

> I think this does what you want...
>
> Sub CreateNameArray()
> Dim X As Long
> Dim R As Range
> Dim N As String
> Set R = Worksheets("Sheet4").Range("A1:A3")
> N = "={"
> For X = 1 To R.Count
> N = N & """" & R(X).Value & ""","
> Next
> N = Left(N, Len(N) - 1) & "}"
> Names.Add Name:="Months", RefersTo:=N
> End Sub
>
> --
> Rick (MVP - Excel)
>
>
> "Steph" <(E-Mail Removed)> wrote in message
> news:25BE7CDF-4005-4ECA-B689-(E-Mail Removed)...
> >I have a list on a worksheet. I would like to convert that list to a named
> > range. Is there a VBA procedure that would do so?
> >
> > For example, in cells A1:A3 I have
> >
> > A1 -> Jan
> > A2 -> Feb
> > A3 -> Mar
> >
> > I would like to convert this list to a defined name called "Months". The
> > defined name dialog box "refers to" input for the name "Months" would look
> > like:
> >
> > ={"Jan","Feb","Mar"}
> >
> > Thanks for your help.
> >
> > --
> > Steph

>
>

 
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
populate array with list of named range LetMeDoIt Microsoft Excel Programming 5 1st May 2008 11:36 PM
Data validation list / named array constant Werner Rohrmoser Microsoft Excel Worksheet Functions 3 19th Mar 2008 12:23 PM
Defined named range (Array list) Sinner Microsoft Excel Programming 2 16th Feb 2008 02:17 PM
Search and replace using a named array on another worksheet Ixtreme Microsoft Excel Programming 2 10th Aug 2007 02:06 PM
Email worksheet from named list on another worksheet =?Utf-8?B?Um9va2llX1VzZXI=?= Microsoft Excel Programming 1 3rd Dec 2006 07:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:25 AM.