Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Vlookup -- LookupV

Hi,

How can I make this work?

Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_value, Error_Msg)
LookupV = Application.WorksheetFunction.VLookup(Lookup_Value ,
Table_Array, Col_Index, Range_value)
If (IsError(LookupV) And Not IsEmpty(Error_Msg)) Then
LookupV = Error_Msg
End Function

It's my first attempt to make a Function.

Ola
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Vlookup -- LookupV

Hi Ola

one way:

Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_value, Error_Msg)
On Error Resume Next
LookupV = Application.WorksheetFunction.VLookup(Lookup_Value ,
Table_Array, Col_Index_Num, Range_value)
If IsEmpty(LookupV) And Not IsEmpty(Error_Msg) Then
LookupV = Error_Msg
End If
End Function

Note the change from Col_Index to Col_Index_Num in the function.

Cheers
JulieD



"Ola" wrote in message
...
Hi,

How can I make this work?

Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_value, Error_Msg)
LookupV = Application.WorksheetFunction.VLookup(Lookup_Value ,
Table_Array, Col_Index, Range_value)
If (IsError(LookupV) And Not IsEmpty(Error_Msg)) Then
LookupV = Error_Msg
End Function

It's my first attempt to make a Function.

Ola



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Vlookup -- LookupV

Application.Vlookup will return #N/A when no value is found. This can be
tested with iserror. When you add Worksheetfunction, it raises a trappable
error (normal VBA error) which can not be handled with iserror. JulieD has
shown you one way to handle the trappable error. This shows you how to use
iserror. As JulieD noted, changed Col_Index to Col_Index_Num as well.

Function LookupV(Lookup_Value, Table_Array As Range, _
Col_Index_Num, Range_value, Error_Msg)
LookupV = Application.VLookup(Lookup_Value, _
Table_Array, Col_Index_Num, Range_value)
If IsError(LookupV) And Not IsEmpty(Error_Msg) Then _
LookupV = Error_Msg
End Function

--
Regards,
Tom Ogilvy


"Ola" wrote in message
...
Hi,

How can I make this work?

Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_value, Error_Msg)
LookupV = Application.WorksheetFunction.VLookup(Lookup_Value ,
Table_Array, Col_Index, Range_value)
If (IsError(LookupV) And Not IsEmpty(Error_Msg)) Then
LookupV = Error_Msg
End Function

It's my first attempt to make a Function.

Ola



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Vlookup -- LookupV

Olla,

Always use Option Explicit at the head of your code to trap this kind of
error.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"JulieD" wrote in message
...
Hi Ola

one way:

Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_value, Error_Msg)
On Error Resume Next
LookupV = Application.WorksheetFunction.VLookup(Lookup_Value ,
Table_Array, Col_Index_Num, Range_value)
If IsEmpty(LookupV) And Not IsEmpty(Error_Msg) Then
LookupV = Error_Msg
End If
End Function

Note the change from Col_Index to Col_Index_Num in the function.

Cheers
JulieD



"Ola" wrote in message
...
Hi,

How can I make this work?

Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_value, Error_Msg)
LookupV = Application.WorksheetFunction.VLookup(Lookup_Value ,
Table_Array, Col_Index, Range_value)
If (IsError(LookupV) And Not IsEmpty(Error_Msg)) Then
LookupV = Error_Msg
End Function

It's my first attempt to make a Function.

Ola





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Vlookup -- LookupV

Thanks JulieD and Tom,

It's close to perfect.

Last thing, how can I return the normal Vlookup Error messages?
=VLOOKUP(test;A1:B6;2;0) -- #NAME?
=VLOOKUP("";A1:B6;2;0) -- #N/A
And no Error_Msg has been filled in (LookupV(6;A1:B6;2;0).

Ola


Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_Value, Error_Msg)
LookupV = Application.VLookup(Lookup_Value, Table_Array, Col_Index_Num,
Range_Value)
If IsError(LookupV) And Not IsEmpty(Error_Msg) Then LookupV = Error_Msg
End Function


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Vlookup -- LookupV

Hi Ola

this is one option, but i'm guessing Tom or Bob (if they're still around)
will come up with something neater.

Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_value, Optional Error_Msg)
If IsMissing(Error_Msg) Then
LookupV = Application.VLookup(Lookup_Value, Table_Array,
Col_Index_Num, Range_value)
Exit Function
End If
On Error Resume Next
LookupV = Application.WorksheetFunction.VLookup(Lookup_Value ,
Table_Array, Col_Index_Num, Range_value)
If IsEmpty(LookupV) Then
LookupV = Error_Msg
End If
End Function


Cheers
julieD

"Ola" wrote in message
...
Thanks JulieD and Tom,

It's close to perfect.

Last thing, how can I return the normal Vlookup Error messages?
=VLOOKUP(test;A1:B6;2;0) -- #NAME?
=VLOOKUP("";A1:B6;2;0) -- #N/A
And no Error_Msg has been filled in (LookupV(6;A1:B6;2;0).

Ola


Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_Value, Error_Msg)
LookupV = Application.VLookup(Lookup_Value, Table_Array, Col_Index_Num,
Range_Value)
If IsError(LookupV) And Not IsEmpty(Error_Msg) Then LookupV = Error_Msg
End Function



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Vlookup -- LookupV

Function LookupV(Lookup_Value, Table_Array As Range, _
Col_Index_Num, Range_value, Optional Error_Msg)
LookupV = Application.VLookup(Lookup_Value, _
Table_Array, Col_Index_Num, Range_value)
If IsError(LookupV) And Not IsMissing(Error_Msg) Then _
LookupV = Error_Msg
End Function

Worked for me.

Usage =LOOKUPV(A2,D2:E11,2,FALSE)
don't put in an argument for Error_Msg unless you want it used. If you put
in "", then it will use that for the error message.

--
Regards,
Tom Ogilvy

"Ola" wrote in message
...
Thanks JulieD and Tom,

It's close to perfect.

Last thing, how can I return the normal Vlookup Error messages?
=VLOOKUP(test;A1:B6;2;0) -- #NAME?
=VLOOKUP("";A1:B6;2;0) -- #N/A
And no Error_Msg has been filled in (LookupV(6;A1:B6;2;0).

Ola


Function LookupV(Lookup_Value, Table_Array As Range, Col_Index_Num,
Range_Value, Error_Msg)
LookupV = Application.VLookup(Lookup_Value, Table_Array,

Col_Index_Num,
Range_Value)
If IsError(LookupV) And Not IsEmpty(Error_Msg) Then LookupV =

Error_Msg
End Function



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default LOOKUPV

Tom and JulieD,

Thanks both for your help!
JulieD your solution worked well but Tom, yours is perfect.

Ola

And it's 15-20% faster then the "normal" formula:
=LOOKUPV(A15000;A1:P30000;5;0;"Nothing")
=IF(ISERROR(VLOOKUP(A15;A1:P30;5;0));VLOOKUP(A15;A 1:P30;5;0);"Nothing")

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
If (Vlookup 0) working, but what if Vlookup cell does not exist Steve Excel Worksheet Functions 18 November 18th 09 07:33 PM
Vlookup in vlookup - taking the result as array name SupperDuck Excel Worksheet Functions 2 June 2nd 07 11:05 AM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
Vlookup -=VLOOKUP(F9,LookUp1!$A$2:$B$1504,2,FALSE) MikeR-Oz New Users to Excel 1 March 22nd 06 09:01 AM
LookupV Relax Excel Worksheet Functions 1 August 24th 05 11:32 AM


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