Search - Find - Replace

donaldv

New Member
Joined
Mar 30, 2009
Messages
1
Hi,

I have the following situation:

In cell A1 to A10 there are names like London, Chicago, Brussels. In the cells B1 to B10 there is a code corresponding to each word. So London corresponds with 1, Chicago with 2, Brussels with 3 etc ...

I have a list from F1 to F100 where the cities are listed randomly. I need to search through the entire list from F1 to F100 and replace each word with the corresponding code.

Can I run this in a macro??

Problem is that the word in the cells A1 to A10 can change, also the corresponding code can change. So I always need to work with the cell number and never with the cel value.

Thanks for your help,
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Welcome to MrExcel Board....

you don't really need a macro, vlookup will do that for you

=vlookup(F1,A1:B100,2,false)
adjust the table A1:B100 to match your area
then copy the formula down
 
Upvote 0
With a macro

Code:
Sub rplc()
Dim i As Long, Found As Range
For i = 1 To 100
    Set Found = Range("A1:A10").Find(what:=Range("F" & i).Value, lookat:=xlWhole)
    If Not Found Is Nothing Then Range("F" & i).Value = Found.Offset(, 1)
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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