Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Newbie vba ranges

Basically I have a cell named "Cell" for convenience. Now that cell
contains a value saying "A1" but this value can change but always
refers to another cell. I want to get the referring cell as a range.
Currently I have:

Dim cell As Range
cell = Range(Range("Cell").Value)

but this doesn't work for some reason.

Can someone please emlighten me?

Thanks,
Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Newbie vba ranges

Mark,

cell is a range object, so you need to use Set:

Set cell = Range(Range("Cell").Value)

Then you can do whatever....

msgbox cell.Address & " is now " & cell.Value

But, in general, it is a bad idea to re-use variable and range names. Better would be

Dim myCell As Range
Set MyCell = Range(Range("Cell").Value)

That way, Excel you won't confuse "Cell" and cell

HTH,
Bernie
MS Excel MVP


wrote in message
oups.com...
Basically I have a cell named "Cell" for convenience. Now that cell
contains a value saying "A1" but this value can change but always
refers to another cell. I want to get the referring cell as a range.
Currently I have:

Dim cell As Range
cell = Range(Range("Cell").Value)

but this doesn't work for some reason.

Can someone please emlighten me?

Thanks,
Mark



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Newbie vba ranges

It is even a better idea to not use terms like Range, Cell, Sheet or
Worksheet for names of cells, sheets or workbooks at all and to always modify
them with extra characters when using them as variables.

" wrote:

Basically I have a cell named "Cell" for convenience. Now that cell
contains a value saying "A1" but this value can change but always
refers to another cell. I want to get the referring cell as a range.
Currently I have:

Dim cell As Range
cell = Range(Range("Cell").Value)

but this doesn't work for some reason.

Can someone please emlighten me?

Thanks,
Mark


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
how copy formula that contains ranges so ranges do not overlap Patty Excel Worksheet Functions 1 November 20th 08 04:15 PM
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
union of named ranges based only on the names of those ranges sloth Excel Programming 3 October 2nd 06 03:18 AM
Copy data in named ranges to a newer version of the same template to identical ranges handstand Excel Programming 0 August 21st 06 03:51 PM
named ranges - changing ranges with month selected gr8guy Excel Programming 2 May 28th 04 04:50 AM


All times are GMT +1. The time now is 05:44 AM.

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"