Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default VLookup question in a macro

Why does an Excel macro stop when a VLookup can't find an
exact match? I would expect it to return N/A in my
variant, but it doesn't. Instead it returns a Run-time
error 1004: Unable to get the VLookup property of the
WorksheetFunction class.

Sample Code:
v = WorksheetFunction.VLookup(r1.Value, ProducerTable, 1,
False)

r1.Value contains producer codes like 61148. I want to
know if that code is in "ProducerTable" which is a one
column range of the valid producer codes.

I was then going to check for ISNA(v) to see if it worked.

OR is there a better way of verifying codes from a range??

THANK YOU!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default VLookup question in a macro

Norm, I suspect that you need to do the following:

v = WorksheetFunction.VLookup(range("r1").Value, range("ProducerTable"), 1,
False)

I am assuming ProduceTable is a range name and that you are using the value
of cell R1 on the active sheet. The Range function returns the range
objects that the vlookup needs.

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


"Norm" wrote in message
...
Why does an Excel macro stop when a VLookup can't find an
exact match? I would expect it to return N/A in my
variant, but it doesn't. Instead it returns a Run-time
error 1004: Unable to get the VLookup property of the
WorksheetFunction class.

Sample Code:
v = WorksheetFunction.VLookup(r1.Value, ProducerTable, 1,
False)

r1.Value contains producer codes like 61148. I want to
know if that code is in "ProducerTable" which is a one
column range of the valid producer codes.

I was then going to check for ISNA(v) to see if it worked.

OR is there a better way of verifying codes from a range??

THANK YOU!



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default VLookup question in a macro

ProducerTable is a range variable in the macro ... not a
Named Range in the workbook. Also, r1 is another range
variable that contains the value that I want searched in
the table ... not the coordinates of the cell.

The formula works until I get a value that's not on the
table ... that's the problem.

Norm


-----Original Message-----
Norm, I suspect that you need to do the following:

v = WorksheetFunction.VLookup(range("r1").Value, range

("ProducerTable"), 1,
False)

I am assuming ProduceTable is a range name and that you

are using the value
of cell R1 on the active sheet. The Range function

returns the range
objects that the vlookup needs.

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros

for Excel


"Norm" wrote in

message
...
Why does an Excel macro stop when a VLookup can't find

an
exact match? I would expect it to return N/A in my
variant, but it doesn't. Instead it returns a Run-time
error 1004: Unable to get the VLookup property of the
WorksheetFunction class.

Sample Code:
v = WorksheetFunction.VLookup(r1.Value, ProducerTable,

1,
False)

r1.Value contains producer codes like 61148. I want to
know if that code is in "ProducerTable" which is a one
column range of the valid producer codes.

I was then going to check for ISNA(v) to see if it

worked.

OR is there a better way of verifying codes from a

range??

THANK YOU!



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VLookup question in a macro

having a 1 as the fourth argument should minimize the number of times when
the value is not found, but you can handle the error

On error resume next
v = WorksheetFunction.VLookup(r1.Value, _
ProducerTable, 1, False)
if err.Number < 0 then
msgbox "Not found
exit sub
End if
On Error goto 0
msgbox "value returned is " & v

--
Regards,
Tom Ogilvy


wrote in message
...
ProducerTable is a range variable in the macro ... not a
Named Range in the workbook. Also, r1 is another range
variable that contains the value that I want searched in
the table ... not the coordinates of the cell.

The formula works until I get a value that's not on the
table ... that's the problem.

Norm


-----Original Message-----
Norm, I suspect that you need to do the following:

v = WorksheetFunction.VLookup(range("r1").Value, range

("ProducerTable"), 1,
False)

I am assuming ProduceTable is a range name and that you

are using the value
of cell R1 on the active sheet. The Range function

returns the range
objects that the vlookup needs.

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros

for Excel


"Norm" wrote in

message
...
Why does an Excel macro stop when a VLookup can't find

an
exact match? I would expect it to return N/A in my
variant, but it doesn't. Instead it returns a Run-time
error 1004: Unable to get the VLookup property of the
WorksheetFunction class.

Sample Code:
v = WorksheetFunction.VLookup(r1.Value, ProducerTable,

1,
False)

r1.Value contains producer codes like 61148. I want to
know if that code is in "ProducerTable" which is a one
column range of the valid producer codes.

I was then going to check for ISNA(v) to see if it

worked.

OR is there a better way of verifying codes from a

range??

THANK YOU!



.



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
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
VLOOKUP question Raz Excel Worksheet Functions 5 February 18th 09 09:51 PM
Vlookup question Daniel Excel Worksheet Functions 9 August 26th 08 01:50 PM
Vlookup question AG Excel Worksheet Functions 2 May 15th 08 01:45 AM
Vlookup question ingleg Excel Discussion (Misc queries) 3 March 31st 06 03:56 PM


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