Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default using vlookup in a custom function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default using vlookup in a custom function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default using vlookup in a custom function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default using vlookup in a custom function

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
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
Possible -- a custom format on text, similar to a VLOOKUP() function? Randy Harmelink Excel Programming 1 November 3rd 06 12:32 AM
Custom function to simplify vlookup formula John James Excel Programming 3 March 15th 06 09:39 PM
Custom Function VLookup Martin Excel Discussion (Misc queries) 1 March 15th 06 08:32 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM


All times are GMT +1. The time now is 01:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"