Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Identify defined name range by another cell value

I have a defined range "MyCity"
Cell C4 on sheet "INFO" has the text MyCity (this changes by code)
The range "MyCity" is on sheet "Index"

how do I in VBA refer to the range "MyCity" or whatever range's name is
shown in cell C4.
My goal is to change the formatting of whatever range is listed in cell C4.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Identify defined name range by another cell value

Have you looked at the excel function INDIRECT?
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Spencer Hutton" wrote in message
...
I have a defined range "MyCity"
Cell C4 on sheet "INFO" has the text MyCity (this changes by code)
The range "MyCity" is on sheet "Index"

how do I in VBA refer to the range "MyCity" or whatever range's name is
shown in cell C4.
My goal is to change the formatting of whatever range is listed in cell
C4.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Identify defined name range by another cell value

range(worksheets("INFO").range("c4").value) will point you at the range you
want.

"Spencer Hutton" wrote:

I have a defined range "MyCity"
Cell C4 on sheet "INFO" has the text MyCity (this changes by code)
The range "MyCity" is on sheet "Index"

how do I in VBA refer to the range "MyCity" or whatever range's name is
shown in cell C4.
My goal is to change the formatting of whatever range is listed in cell C4.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Identify defined name range by another cell value

I have this code and it does not work, i get an error. The range whose name
is in C4 is on another sheet, i am not sure if that matters.

Dim s As String

s = Sheets("INFO").Range("C4").Value
Range(s).Locked = True


"Spencer Hutton" wrote:

I have a defined range "MyCity"
Cell C4 on sheet "INFO" has the text MyCity (this changes by code)
The range "MyCity" is on sheet "Index"

how do I in VBA refer to the range "MyCity" or whatever range's name is
shown in cell C4.
My goal is to change the formatting of whatever range is listed in cell C4.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Identify defined name range by another cell value

What error do you get? I've just tried your code and it works on mine.

Do you have any spaces in the cell containing MyCity, ie is the actual value
"MyCity " rather than "MyCity"

"Spencer Hutton" wrote:

I have this code and it does not work, i get an error. The range whose name
is in C4 is on another sheet, i am not sure if that matters.

Dim s As String

s = Sheets("INFO").Range("C4").Value
Range(s).Locked = True


"Spencer Hutton" wrote:

I have a defined range "MyCity"
Cell C4 on sheet "INFO" has the text MyCity (this changes by code)
The range "MyCity" is on sheet "Index"

how do I in VBA refer to the range "MyCity" or whatever range's name is
shown in cell C4.
My goal is to change the formatting of whatever range is listed in cell C4.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Identify defined name range by another cell value

i changed it to:

Dim s As String

s = ActiveWorkbook.Worksheets("INFO").Range("C4").Valu e
ActiveWorkbook.Worksheets("Index").Range(s).Locked = True

and it works.

"Sam Wilson" wrote:

What error do you get? I've just tried your code and it works on mine.

Do you have any spaces in the cell containing MyCity, ie is the actual value
"MyCity " rather than "MyCity"

"Spencer Hutton" wrote:

I have this code and it does not work, i get an error. The range whose name
is in C4 is on another sheet, i am not sure if that matters.

Dim s As String

s = Sheets("INFO").Range("C4").Value
Range(s).Locked = True


"Spencer Hutton" wrote:

I have a defined range "MyCity"
Cell C4 on sheet "INFO" has the text MyCity (this changes by code)
The range "MyCity" is on sheet "Index"

how do I in VBA refer to the range "MyCity" or whatever range's name is
shown in cell C4.
My goal is to change the formatting of whatever range is listed in cell C4.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Identify defined name range by another cell value

I was just about to post this combined line in which the Range is embedded
with another Range for that...

Sheets("Index").Range(Sheets("Info").Range("C4").V alue).Locked = True

As you can see, there is no need for the intermediate "s" variable in order
to carry the defined name forward.

Rick


"Spencer Hutton" wrote in message
...
i changed it to:

Dim s As String

s = ActiveWorkbook.Worksheets("INFO").Range("C4").Valu e
ActiveWorkbook.Worksheets("Index").Range(s).Locked = True

and it works.

"Sam Wilson" wrote:

What error do you get? I've just tried your code and it works on mine.

Do you have any spaces in the cell containing MyCity, ie is the actual
value
"MyCity " rather than "MyCity"

"Spencer Hutton" wrote:

I have this code and it does not work, i get an error. The range whose
name
is in C4 is on another sheet, i am not sure if that matters.

Dim s As String

s = Sheets("INFO").Range("C4").Value
Range(s).Locked = True


"Spencer Hutton" wrote:

I have a defined range "MyCity"
Cell C4 on sheet "INFO" has the text MyCity (this changes by code)
The range "MyCity" is on sheet "Index"

how do I in VBA refer to the range "MyCity" or whatever range's name
is
shown in cell C4.
My goal is to change the formatting of whatever range is listed in
cell C4.


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
Dynamic Range Defined by Value of Cell Domenick Excel Worksheet Functions 7 December 18th 09 01:53 PM
Selecting a range defined in a cell Alex Excel Programming 9 July 2nd 07 04:22 PM
User Defined Function - Can we identify the cell it's called from Barb Reinhardt Excel Programming 5 March 21st 07 09:17 PM
Copying A Range of Cells From one Sheet to Another - Error Application Defined or Object Defined Matt[_39_] Excel Programming 3 July 25th 06 01:13 AM
How do I identify a range based on cell value? HBF[_2_] Excel Programming 8 June 16th 06 06:06 PM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"