Searching Sheet2 with Text from Sheet1

nzepeda

Board Regular
Joined
Nov 11, 2010
Messages
58
I am going to attempt to write a macro that will be searching Sheet2, which has the name of different locations down along column A22 to A375 and 2 columns over has a corresponding Code for location. To search Sheet2 I will need to use a string from Sheet1. Sheet1 along B5 to H5 will have the strings I will be using.

Somehow I want to write a macro that will assign the text in B5 to a string variable. It must then use this variable to search Sheet2 for the text, once found, offset 2 columns over and copy the code. After this paste this code into Sheet3 down along A3.

Where this will get tricky is that the text from Sheet1 will not always be found right away in Sheet2, sometimes this text will lead with 1 to 3 characters followed by a space. I will have to have the code take this into account, by having it loop somehow if not found the first time, to shift over 1 space at a time and search again.

There may also be similar locations on Sheet2, but which have different codes. So if multiple locations match the string I must have it bring up a userform of some sort that will have the locations to have me choose which is the proper 1.

Any help would be much appreciated. Will be working on this for the next few days. If needed I will try to post examples of how the sheets may look.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,015
Messages
5,834,938
Members
430,327
Latest member
Mr_Himalayan778

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