PC Review


Reply
Thread Tools Rate Thread

Can I change the reference to a named range via VBA?

 
 
Bassman62
Guest
Posts: n/a
 
      21st Mar 2009
I have a range named "Home" that refers to: =Sheet1!$A$1.
What Macro code would I use to change the reference?
Thanks for any advice.


 
Reply With Quote
 
 
 
 
Bassman62
Guest
Posts: n/a
 
      21st Mar 2009
Clarification:
The named range "Home" is a defined name in the worksheet, not a variable
in any code.

"Bassman62" <(E-Mail Removed)> wrote in message
news:O$(E-Mail Removed)...
>I have a range named "Home" that refers to: =Sheet1!$A$1.
> What Macro code would I use to change the reference?
> Thanks for any advice.
>
>



 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      21st Mar 2009
Here is how I do it. Say you want to move the named range from A2 to B3.

Sub dk()
ActiveWorkbook.Names("Home").Delete
ActiveWorkbook.Names.Add "test", RefersTo:="=Sheet1!$B$3"
End Sub

It will also work for a range like Sheet1!$A$2:$C$12


"Bassman62" <(E-Mail Removed)> wrote in message
news:O$(E-Mail Removed)...
>I have a range named "Home" that refers to: =Sheet1!$A$1.
> What Macro code would I use to change the reference?
> Thanks for any advice.
>
>



 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      21st Mar 2009
Sorry about the typo, should have been Home in both places.

Sub dk()
ActiveWorkbook.Names("Home").Delete
ActiveWorkbook.Names.Add "Home", RefersTo:="=Sheet1!$B$3"
End Sub



"Bassman62" <(E-Mail Removed)> wrote in message
news:O$(E-Mail Removed)...
>I have a range named "Home" that refers to: =Sheet1!$A$1.
> What Macro code would I use to change the reference?
> Thanks for any advice.
>
>



 
Reply With Quote
 
Bassman62
Guest
Posts: n/a
 
      21st Mar 2009
Thank you very much.
This helps a great deal!
Best Regards


"JLGWhiz" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Sorry about the typo, should have been Home in both places.
>
> Sub dk()
> ActiveWorkbook.Names("Home").Delete
> ActiveWorkbook.Names.Add "Home", RefersTo:="=Sheet1!$B$3"
> End Sub
>
>
>
> "Bassman62" <(E-Mail Removed)> wrote in message
> news:O$(E-Mail Removed)...
>>I have a range named "Home" that refers to: =Sheet1!$A$1.
>> What Macro code would I use to change the reference?
>> Thanks for any advice.
>>
>>

>
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Mar 2009
You can just reassign the Name to a different range:

worksheets("sheet99").range("z9").name = "Home"




Bassman62 wrote:
>
> I have a range named "Home" that refers to: =Sheet1!$A$1.
> What Macro code would I use to change the reference?
> Thanks for any advice.


--

Dave Peterson
 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      22nd Mar 2009


> ActiveWorkbook.Names("Home").Delete


You don't need to delete the name, although it is harmless to do so
and it adds clarity to the logic of the code.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sat, 21 Mar 2009 19:33:40 -0400, "JLGWhiz" <(E-Mail Removed)>
wrote:

>Sorry about the typo, should have been Home in both places.
>
>Sub dk()
> ActiveWorkbook.Names("Home").Delete
> ActiveWorkbook.Names.Add "Home", RefersTo:="=Sheet1!$B$3"
>End Sub
>
>
>
>"Bassman62" <(E-Mail Removed)> wrote in message
>news:O$(E-Mail Removed)...
>>I have a range named "Home" that refers to: =Sheet1!$A$1.
>> What Macro code would I use to change the reference?
>> Thanks for any advice.
>>
>>

>

 
Reply With Quote
 
Bassman62
Guest
Posts: n/a
 
      22nd Mar 2009
Thanks to Chip and Dave.
This helps my understanding of referencing named ranges in VBA.

"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You can just reassign the Name to a different range:
>
> worksheets("sheet99").range("z9").name = "Home"
>
>
>
>
> Bassman62 wrote:
>>
>> I have a range named "Home" that refers to: =Sheet1!$A$1.
>> What Macro code would I use to change the reference?
>> Thanks for any advice.

>
> --
>
> Dave Peterson



 
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
Named range in chart - any way to change the workbook reference with VBA Graham Whitehead Microsoft Excel Programming 1 23rd Oct 2007 03:02 PM
automatic range - named range give me circular reference... George Thorogood Microsoft Excel Misc 0 22nd Feb 2007 07:53 PM
Reference a named range =?Utf-8?B?Sm9obiBNLg==?= Microsoft Excel Programming 2 8th Oct 2005 07:42 AM
Change named range to "A1" style reference mb Microsoft Excel Discussion 1 12th Feb 2004 11:55 PM
How to change a global named reference to a sheet named reference? \Rob Hetlam\ Microsoft Excel Misc 1 26th Oct 2003 08:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:16 PM.