Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Named range scope question (using application.match)

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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Named range scope question (using application.match)

sVal = Sheet11.Range("B5").Value
JobVal = Application.Match(sVal, Range("Position"), 0)

Range("Position") in a sheet module is equivalent to

me.Range("Position")

since the named range position isn't in that sheet, you get an error.

Try
Application.Range("Position")

instead. Or if that doesn't work then try

thisworkbook.names("Position").ReferstoRange



--
Regards,
Tom Ogilvy


"Keith" wrote:

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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Named range scope question (using application.match)

Excellent- thank you Tom!!

"Tom Ogilvy" wrote in message
...
sVal = Sheet11.Range("B5").Value
JobVal = Application.Match(sVal, Range("Position"), 0)

Range("Position") in a sheet module is equivalent to

me.Range("Position")

since the named range position isn't in that sheet, you get an error.

Try
Application.Range("Position")

instead. Or if that doesn't work then try

thisworkbook.names("Position").ReferstoRange



--
Regards,
Tom Ogilvy


"Keith" wrote:

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
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
Named Range Scope Slim Slender Excel Discussion (Misc queries) 0 December 13th 09 02:41 AM
Deleting all named ranges that have a workbook scope Babymech Excel Discussion (Misc queries) 3 February 19th 09 04:21 PM
application.match question Chip Smith Excel Programming 1 March 30th 06 08:28 PM
Defined Name Range (Application.Match) PCLIVE Excel Programming 10 October 20th 05 02:54 PM
Application Event Scope Problem [email protected] Excel Programming 2 October 7th 05 11:02 PM


All times are GMT +1. The time now is 01:17 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"