Dyanic Vlookup Function

Vanis

New Member
Joined
Jan 18, 2005
Messages
3
Hello! Long time reader, first time poster. I have a bit of an issue that needs resolving.

I'm creating a Excel Sheet whereby it pulls data from a variety of other Excel Sheets based on Company names. Each Excel sheet contains multiple contract numbers.

Using someone's code I found here (Apologies for not remembering who) I was able to change Vlookup to Vlookupnth so that it would display multiple matches by changing a number at the end of the formula.

Now I'm trying to make the sheet a little dynamic so that it creates the appropriate amount of returns. What I need to know is what VBA code is required to make it create a Vlookup statement built of changing variables.

Example: =Vlookupnth($A$1,[Path to Excel File],[Range from that file],[Column],[Return#])

I need to be able to have a macro go to specific ranges and input the above statement but with the [Variable]s filled in.

Any help would be greatly appreciated.

Cheers,
SF
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi SF,

We can't answer this question definitively without seeing the code for Vlookupnth, but my best guess would be that you could call it as follows:

Example: =Vlookupnth(LUrange,LUpath,LUtable,LUcol,LUreturn)

where

LUrange is a Range variable that would be set using a statement like

Set LUrange = Worksheets("Sheet1").Range("A1")

LUpath is a String variable set using a statement like

LUpath = "C:/My Documents/Test Database.xls"

LUtable is a String variable set using a statement like

LUtable = "Sheet3!B4:Z300"

LUcol is an Integer variable set using a statement like

LUcol = 12

LUreturn is an Integer variable set using a statement like

LUreturn = 6

My guesses are most uncertain on LUtable and LUpath. since there are a plethora of ways these could be defined that would make sense. Defining a file path as a string really only makes sense if the file is closed at the time the routine is run and Excel must open the file before reading the table data. If the file is already open, then LUpath would only need to be a workbook name, not a complete path, which is why I assumed it was closed.

I hope this helps.

Damon
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,086
Members
448,944
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top