Search value in another workbook

SuperBaby

New Member
Joined
Apr 17, 2013
Messages
24
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
ABC
1AB6675-30 Confirm

<TBODY>
</TBODY>

Workbook2
ABC
1AB6675-30.300001
2AC53555-25.100002

<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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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...
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,037
Members
448,543
Latest member
MartinLarkin

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