You are here:

Excel/Custom Function for V_Lookup

Advertisement


Question
Test_Formula_Image
Test_Formula_Image  
Hi Jerry,

I was trying to make a custom function which can mimic vlookup. but I couldnot get this working. Please help me with this.
I have put this code in Personal.xlsb :

What i am trying is to employ Match and index functions to mimic Vlookup, but its not working.
-----------------------
Function DLookup(LookupRange As Range, FindValue As String, RowRange As Range, ColNum As Integer)

Dim Result As Variant
Result = Application.WorksheetFunction.Index(LookupRange, Application.WorksheetFunction.Match(FindValue, RowRange, 0), ColNum)

End Function
------------------------------

This is giving me zero as the result.

Answer
Like so:

Function DLookup(LookupTable As Range, FindValue As String, LookupRange As Range, ReturnCol As Long)

DLookup = Application.WorksheetFunction.Index(LookupTable, Application.WorksheetFunction.Match(FindValue, LookupRange, 0), ReturnCol)

End Function

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jerry Beaucaire

Expertise

Excel Formulas, macros, automation. Microsoft Excel MVP - 2010. Code site with free code snippets and techniques: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files

Experience

Microsoft Excel MVP - 2010. I have my own extensive Excel help/code site: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files ===================== I have been offering free assistance as an Excel aid on many web sites for many years: (http://www.excelforum.com - JBeaucaire) ======== (http://www.askmehelpdesk.com/spreadsheets - JBeaucaire) ======= (http://www.mrexcel.com/forum - jbeaucaire)

Education/Credentials
Bachelor's Degree from Azusa Pacific University in Mathematics and Music Composition

Awards and Honors
Microsoft Excel MVP 2010

©2016 About.com. All rights reserved.