Vlookup within an array

beachie2037

New Member
Joined
Jan 6, 2005
Messages
21
Hi,

I have an array of data thats being called in a macro. Is it possible to run a vlookup in the macro array based on a cell refence on the page. Basically I want to use the customer number to reference a cell of data (customer name) that will be on a row corresponding to the cell reference.

See below for example of what I WOULD LIKE TO DO

Dim EditCust(3)
EditCust(0) = Range("A1")
EditCust(1) = VLOOKUP(A1,CustomerDB!A5:D7,2,FALSE)
EditCust(2) = Range("A3")

Obviously this doesnt work - is it possible to do what I want to do?

ANy help appreciated.


Steve
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi Steve:

instead of ...

VLOOKUP(A1,CustomerDB!A5:D7,2,FALSE)

try

evaluate("=VLOOKUP(A1,CustomerDB!A5:D7,2,FALSE)")

I hope this helps!
 
Upvote 0
Steve

try something like

Code:
editcust(1) = worksheetfunction.vlookup(range("a1"),sheets("customerDB").range("a5:d7"),2,false)


Tony
 
Upvote 0
Perhaps try:

Code:
EditCust(1) = Application.WorksheetFunction.VLookup(Range("A1").Value, Worksheets("CustomerDB").Range("A5:D7"), 2, 0)

Hope that helps!

EDIT: Both work. Perhaps someone will 'splain to us why you don't need the Application Object in this case. I don't know why.
 
Upvote 0

Forum statistics

Threads
1,222,246
Messages
6,164,802
Members
451,917
Latest member
WEB78

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