View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default worksheetfunction.vlookup in vba

Worked okay for me. You will get an error if no matches are found.

You could make your wrapper function return a specified value (say 0) if
VLOOKUP returns N/A (meaning it found no matches).

Function StLookup(strSearch As String, tableName As Range, position)

With Application
If .IsNA(.VLookup(strSearch, tableName, position, False)) Then
StLookup = 0
Else: StLookup = .VLookup(strSearch, tableName, position, False)
End If
End With

End Function

If you have a lot of lookups, you may want to reconsider using a UDF as they
are slower than Excels native functions and could bog down your computer.


"pmoon7" wrote:


Function StLookup(strSearch As String, tableName As Range, position)
StLookup = WorksheetFunction.VLOOKUP(strSearch, tableName, position,
False)

End Function

I can't seem to trace the error #value return from this function. My
original vlookup is getting wieldy -- too many ifs -- and I want to
move it within the vba function so I can organize it better.


--
pmoon7
------------------------------------------------------------------------
pmoon7's Profile: http://www.excelforum.com/member.php...o&userid=30808
View this thread: http://www.excelforum.com/showthread...hreadid=504698