Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Adam at GTOFL
 
Posts: n/a
Default How do I create a formula to retun a value of 0 (zero) when a VLO.

When searching multiple tables with a V or HLOOKUP formula, I want a search
that doe not find anything to result in a zero instead of an error (#N/A)

I have tried a variations of IF formulas but am missing something.

Thanks
  #3   Report Post  
Ola
 
Posts: n/a
Default

You could also use this formula:
=LOOKUPV(C1,A1:B100,2,0,0) or
=LOOKUPV(C1,A1:B100,2,0,"")


But first
1. Press Alt+F11. Insert Module. Copy and Paste the below:

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

Make sure the VBA code is only 4 rows!
The LOOKUPV formula is Shorter and is Faster then VLOOKUP

Ola Sandstrom

  #4   Report Post  
Myrna Larson
 
Posts: n/a
Default

Do you mean it's faster than the 2 calls that are used in a formula like

=IF(ISNA(VLOOKUP(....)),0,VLOOKUP(...))

That could be, but LOOKUPV(...) certainly can't be faster than =VLOOKUP(...)


On Sat, 19 Feb 2005 11:21:02 -0800, Ola wrote:

You could also use this formula:
=LOOKUPV(C1,A1:B100,2,0,0) or
=LOOKUPV(C1,A1:B100,2,0,"")


But first
1. Press Alt+F11. Insert Module. Copy and Paste the below:

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

Make sure the VBA code is only 4 rows!
The LOOKUPV formula is Shorter and is Faster then VLOOKUP

Ola Sandstrom


  #5   Report Post  
Ola
 
Posts: n/a
Default

You are right Myrna, VBA code is always slower. So VLOOKUP should always be
used when Error handling is not needed.

However in this case, I've done some 20.000 rows test and LOOKUPV has been
faster, since it only does the VLOOKUP procedure once not twice. So the main
reson for this post is to offer an alternative - which I think work. But do
test it.

Ola Sandstrom

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
How do I create a formula that would allow me to subtract from a d Justlearning New Users to Excel 5 January 27th 05 09:47 PM
Create formula Leo Excel Worksheet Functions 2 January 19th 05 10:16 PM
create a chart with a formula anon Charts and Charting in Excel 1 December 15th 04 08:55 PM
Create a formula that determines a date-sensitive File-Name from w stan-the-man Excel Worksheet Functions 0 November 17th 04 03:39 PM
How do I create a formula in Excel that will countif or sumif bef. bkclark Excel Worksheet Functions 4 November 10th 04 05:30 PM


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