View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Custom function to simplify vlookup formula

Public Function myLookup(lookup_value, _
table_array As Range, _
col_index_num As Long, _
Optional range_lookup As Boolean = True)
Dim tmp
On Error Resume Next
tmp = Application.VLookup(lookup_value, table_array, col_index_num,
range_lookup)
On Error GoTo 0
If IsError(tmp) Then
myLookup = ""
Else
myLookup = tmp
End If
End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"John James" wrote in message
...
I want to have custom functions that will simplify vlookups (and other
formulas) which have imbedded "if" formulas to eliminate errors. e.g.This
formula provided in a previous posting is ugly and somewhat annoying:
=IF(ISERROR(VLOOKUP($A2,Stock,2,0)),"",VLOOKUP($A2 ,Stock,2,0))

Can I replace it with a custom function that works the same but looks
something like this:
=MyVLookup($A2,Stock,2,0)