HighTechTalks DotNet Forums  

Another (probably simple) scope question- named ranges in sheet vs. module code

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss Another (probably simple) scope question- named ranges in sheet vs. module code in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Keith
 
Posts: n/a

Default Another (probably simple) scope question- named ranges in sheet vs. module code - 02-01-2007 , 03:40 PM






XL2003, sheet names are sheet codenames not the tab names.

I have a named range on Sheet1 called "Positions"

The following code in a code module returns the correct match, and evaluates
to a value of 3
sVal = Sheet11.Range("B5").Value
JobVal = Application.Match(sVal, Range("Position"), 0)

The /exact/ same code, in a sub behind Sheet11 returns a 1004 runtime error.
sVal = Sheet11.Range("B5").Value
JobVal = Application.Match(sVal, Range("Position"), 0) '<-- crashes here

sVal in both cases pulls the correct value. The error occurs when trying to
calculate the the JobVal value.

Is there some reason or rule that says a sheet can't use application.match
on a named range from a different sheet? I use named ranges sometimes for
data validation lists on other sheets, so I'd think it should be ok, but I
can't figure out why this isn't working... or an appropriate workaround. I
suppose I could call a sub in a module and put this value in a public
variable, but I'd like to understand why it doesn't work in the first place!

Thank you,
Keith





Reply With Quote
  #2  
Old   
Keith
 
Posts: n/a

Default Re: Another (probably simple) scope question- named ranges in sheet vs. module code - 02-01-2007 , 03:51 PM






oops, apparently I had the wrong group selected- my apologies, I'll repost
to the originally intended group.
Keith

"Keith" <fake_address (AT) not_a_real_address (DOT) org.net.com> wrote

Quote:
XL2003, sheet names are sheet codenames not the tab names.

I have a named range on Sheet1 called "Positions"

The following code in a code module returns the correct match, and
evaluates to a value of 3
sVal = Sheet11.Range("B5").Value
JobVal = Application.Match(sVal, Range("Position"), 0)

The /exact/ same code, in a sub behind Sheet11 returns a 1004 runtime
error.
sVal = Sheet11.Range("B5").Value
JobVal = Application.Match(sVal, Range("Position"), 0) '<-- crashes here

sVal in both cases pulls the correct value. The error occurs when trying
to calculate the the JobVal value.

Is there some reason or rule that says a sheet can't use application.match
on a named range from a different sheet? I use named ranges sometimes for
data validation lists on other sheets, so I'd think it should be ok, but I
can't figure out why this isn't working... or an appropriate workaround. I
suppose I could call a sub in a module and put this value in a public
variable, but I'd like to understand why it doesn't work in the first
place!

Thank you,
Keith







Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.