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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Yogi Anand

MrExcel MVP
Joined
Mar 12, 2002
Messages
11,454
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

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Steve

try something like

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


Tony
 
Upvote 0

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
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,195,948
Messages
6,012,475
Members
441,701
Latest member
vnkendijs

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
Top