Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Problem getting the value of a Named Range in code

I'm not very experienced with Excel VBA yet, so I often use the
immediate window to try out various syntax before coding it up.

I found something that works in the immediate window when nothing is
running:

? Range("OnSiteRate").value

does NOT work when the code is run or in the immediate window with the
code paused due to the error. I found a workaround:

? ThisWorkbook.Names("OnSiteRate").RefersToRange

but I'm curious as to why this doesn't work in both circumstances.

Thanks
tbone
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem getting the value of a Named Range in code

Both methods work for me.

If you tried to used

Range("OnSiteRate").value

in a sheet module and the named range "OnSiteRate" was on another sheet,
then you have to qualify it with the sheet name where it exists because an
unqualifed "Range" reference in a sheet module is the same as saying

me.Range

In a general module, you don't have this problem.

--
Regards,
Tom Ogilvy



"tbone" wrote in message
...
I'm not very experienced with Excel VBA yet, so I often use the
immediate window to try out various syntax before coding it up.

I found something that works in the immediate window when nothing is
running:

? Range("OnSiteRate").value

does NOT work when the code is run or in the immediate window with the
code paused due to the error. I found a workaround:

? ThisWorkbook.Names("OnSiteRate").RefersToRange

but I'm curious as to why this doesn't work in both circumstances.

Thanks
tbone



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
VBA code to affect value of a named range Dave O Excel Discussion (Misc queries) 5 August 25th 06 10:12 PM
Named ranges vs setting range in code Tim Excel Programming 2 February 24th 06 02:50 AM
named range problem Rbp9ad[_2_] Excel Programming 4 December 1st 05 10:21 PM
How to conditional color a named range in VBA code mark engineer Excel Programming 1 October 31st 05 03:12 AM
Named Range Fails in VBA Code Dean Hinson[_3_] Excel Programming 3 January 24th 05 03:48 PM


All times are GMT +1. The time now is 04:23 PM.

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"