Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a database style spreadsheet that I use a lot and is stored on
our intranet. I use a vlookup to find information about products in a database. I look up the unique product name then choose the column that matches a specific fieldname text. It looks something like this: =VLOOKUP(A2,ExternalRange,MATCH(F1,ExternalFieldna me,0),FALSE) There are only two changing variables in this formula so I've tried to create a custom function that already has the external database and fieldname range built in, but to no avail. Anyone suggest help? I guess that the custom function would only need to know the A2 and the F1 bit in the example above. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this. You may change Variant to something more specific.
Function MyLookUp(arg1 As Range, arg2 As Range) As Variant MyLookUp = Application.VLookup(arg1, Range("ExternalRange"), _ Application.Match(arg2, Range("ExternalFieldname"), 0), False) End Function Hth, Merjet |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Merjet for your help. I've been struggling with this for a
while , I've tried this and am having trouble defining the external range. The code below returns #VALUE! I wonder if there is something obvious that I'm doing wrong? Function MyLookUp(Acronym As Range, Fieldname As Range) As Variant Dim R21Data As Range Dim R21Fields As Range Dim wbk As Workbook Set wbk = Workbooks.Open(Filename:= _ "http://nonsolus/GlobalReports/public/yesterday/Report21.xls") Set R21Data = wbk.Worksheets("Data").Range("$A$7:$DV$1954") 'Data Range in External Workbook Set R21Fields = wbk.Worksheets("Data").Range("$A$7:$DV$7") 'Header Range in External Workbook MyLookUp = Application.VLookup(Acronym, R21Data, Application.Match(R21Fields, Range("ExternalFieldname"), 0), False) End Function |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for the advice. I'm now struggling to understand how to define
the external range. So far I have this but the result is "#VALUE!" Function MyLookUp(Acronym As Range, Fieldname As Range) As Variant Dim R21Data As Range Dim R21Fields As Range Dim wbk As Workbook Set wbk = Workbooks.Open(Filename:= _ "http://intranet/yesterday/Report21.xls") Set R21Data = wbk.Worksheets("Data").Range("$A$7:$DV$1954") Set R21Fields = wbk.Worksheets("Data").Range("$A$7:$DV$7") MyLookUp = Application.VLookup(Acronym, R21Data, Application.Match(Fieldname, R21Fields, 0), False) End Function |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Possible -- a custom format on text, similar to a VLOOKUP() function? | Excel Programming | |||
Custom function to simplify vlookup formula | Excel Programming | |||
Custom Function VLookup | Excel Discussion (Misc queries) | |||
Emulate Index/Match combo function w/ VBA custom function | Excel Worksheet Functions | |||
Adding a custom function to the default excel function list | Excel Programming |