Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Macro to create Name Ranges!

Hello All,

My main purpose is to have a VB code that upon pressing a button, recreates
all my named ranges automatically for all sheets in my workbook. I
appreciate all your help in this matter. Here is my problem:

Using Excel 2003: Let's say, in the CONSTANT sheet, I have a cell A1 which
contains a reference to a cell location of another sheet in the same
workbook. I am trying to create a name range in the VB code.

Let's say Constant!A1 contains the ('='FY2009-FSA Health Tracker'!A2) value.
In my VB code, I have the following summerized code:
Dim strRefersTo As String
{ I have code to select the CONSTANT sheet here....}
Then I have:
strRefersTo = Activesheet.Range("A1").value 'this string should have the
('='FY2009-FSA Health Tracker'!A2) value at this point.

Next I tried to assign it to a name range:
ActiveWorkbook.Names.Add Name:="TEST", RefersToR1C1:=strRefersTo

The code works, but when I check the ReferTo section of the TEST name range
in excel (INSERT-NAME-Define), it has the

value of: ='FY2009-FSA Health Tracker'!'A2'
Instead of: ='FY2009-FSA Health Tracker'!A2

How can I make this work?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Macro to create Name Ranges!

Try using RefersTo instead of RefersToR1C1.

Also consider using an absolute reference for your A2 cell reference (to fix
the cell reference in the Name assignment) when assigning the string value
to the strRefersTo variable.

--
Rick (MVP - Excel)


"LABKHAND" wrote in message
...
Hello All,

My main purpose is to have a VB code that upon pressing a button,
recreates
all my named ranges automatically for all sheets in my workbook. I
appreciate all your help in this matter. Here is my problem:

Using Excel 2003: Let's say, in the CONSTANT sheet, I have a cell A1
which
contains a reference to a cell location of another sheet in the same
workbook. I am trying to create a name range in the VB code.

Let's say Constant!A1 contains the ('='FY2009-FSA Health Tracker'!A2)
value.
In my VB code, I have the following summerized code:
Dim strRefersTo As String
{ I have code to select the CONSTANT sheet here....}
Then I have:
strRefersTo = Activesheet.Range("A1").value 'this string should have the
('='FY2009-FSA Health Tracker'!A2) value at this point.

Next I tried to assign it to a name range:
ActiveWorkbook.Names.Add Name:="TEST", RefersToR1C1:=strRefersTo

The code works, but when I check the ReferTo section of the TEST name
range
in excel (INSERT-NAME-Define), it has the

value of: ='FY2009-FSA Health Tracker'!'A2'
Instead of: ='FY2009-FSA Health Tracker'!A2

How can I make this work?

Thanks


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
Create 3 Ranges in 1 Arlen Excel Discussion (Misc queries) 4 August 12th 08 05:36 PM
Create a collection of ranges Dana DeLouis Excel Programming 0 January 3rd 07 08:35 PM
Create a collection of ranges Norman Jones Excel Programming 0 January 3rd 07 07:58 PM
Create named ranges loopoo[_25_] Excel Programming 2 December 22nd 05 01:16 PM
Using VB to to create named ranges PC[_3_] Excel Programming 7 May 19th 05 10:57 AM


All times are GMT +1. The time now is 12:37 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"