# Search value in another workbook

#### SuperBaby

##### New Member
Hi,

I would like to ask for vba code to search the given value in another workbook and return the corresponding cell back to the original workbook. Can anyone help please?

Workbook1
 A B C 1 AB6675-30 Confirm

<TBODY>
</TBODY>

Workbook2
 A B C 1 AB6675-30.3 00001 2 AC53555-25.1 00002

<TBODY>
</TBODY>

I would like to have cell A1 in workbook1 to be searched in column A workbook2 and return value in column B to workbook 1 column C.

Thank you very much.

### Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi,

Can you use a formula?...

Workbook2 (Test)

Excel Workbook
ABC
1Data1Data2
2AB6675-30.300001
3AC53555-25.100002
4
Sheet8

Workbook1

Excel Workbook
ABCD
1Data1Data2Data3
2AB6675-30Confirm00001
3AC53555-25.1Test00002
4
Sheet4

**Is the value AB6675-30 in your example correct or should it be AB6675-30.3?
I have assumed it is AB6675-30 so I have used Wild cards "*" in the Vlookup.
If it should be AB6675-30.3 then the formula can be changed to this...
=VLOOKUP(A2,[Test.xls]Sheet8!A\$2:B\$3,2,0)

You can change the Workbook reference (in bold) to suit your Workbook name.
=VLOOKUP("*"&A2&"*",[Test.xls]Sheet8!A\$2:B\$3,2,0)

You can change the Sheet reference (in bold) to suit your Sheet name.
=VLOOKUP("*"&A2&"*",[Test.xls]Sheet8!A\$2:B\$3,2,0)

You will obviously need to change the cell references to suit your layout.

I hope this helps.

Ak

Hi Akashwani,

Thanks for the reply. I would like to have it in VBA code. I have the button provided for my user to search the value they want. they insert it in workbook1 A1 and press the button and they get the answer in column C which after that it is no use. In addition, I have written the code to open another workbook only when this needs to be search. Hope u understand. Thank you very much

Hi,

I'm sorry, but I don't write or understand VBA that is why I gave a formula solution.
If you don't get any further input on this post, I suggest that you start a new post with a title like VBA Vlookup different Workbook copy/paste result.

Ak

Thank y ou so much

It's going to end up being very similar to the formula, but in code, you'll need a way to pass the lookup value in.

something like this, but there will be more to it to snag the correct cell reference, unless what you're looking up will always be in cell A2.

Code:
``cells(1, "C") = Evaluate("=VLOOKUP(""*""&A2&""*"",[Test.xls]Sheet8!A\$2:B\$3,2,0)")``

I always have trouble figuring out where to put all the quotes when doing it in VBA, but this will give you the general idea.

Hi rjwebgraphix,

Thank you very much for your help but I am too new to understand where to put this code and what is needed before that too. I will give a try with knowledge I have and if I can figure it out (with luck), will let you know...

Replies
3
Views
135
Replies
0
Views
123
Replies
3
Views
317
Replies
1
Views
212
Replies
0
Views
196

1,196,487
Messages
6,015,496
Members
441,898
Latest member
kofafa

### 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.

### Which adblocker are you using?

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

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