Thread: Macro-replace
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Macro-replace

You can add those conditions to the below two arrays...like below and then
use the same macro...

Atlanta; New York; Denver to Jim
Las Vegas, Detroit; Washington to John
Chicago; Ohio, Los Angeles to Mary

arrFind = Array("Atlanta", "New York" , "Denver", "Las Vegas", "Chicago")
arrReplace = Array("Jim", "Jim","Jim", "John", "Mary")


If this post helps click Yes
---------------
Jacob Skaria


"puiuluipui" wrote:

Hi, my first post was a little bit wrong.
I need to change a few cities with a name:

Atlanta; New York; Denver to Jim
Las Vegas, Detroit; Washington to John
Chicago; Ohio, Los Angeles to Mary

Sorry for my first post.
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Try the below...

Sub Macro1()

Dim intTemp As Integer
Dim arrFind As Variant, arrReplace As Variant

arrFind = Array("Jim", "John", "Mary")
arrReplace = Array("Atlanta", "Las Vegas", "Chicago")

For intTemp = 0 To UBound(arrFind)
Cells.Replace What:=arrFind(intTemp), _
Replacement:=arrReplace(intTemp), _
LookAt:=xlWhole, SearchOrder:=xlByRows
Next

End Sub

;If you are looking for strings within the cell replace xlWhole with xlPart

If this post helps click Yes
---------------
Jacob Skaria


"puiuluipui" wrote:

Hi, i need a macro to replace:
Jim with Atlanta
John with Las Vegas
Mary with Chicago
.....
This criteria to be inside macro.
Can this be done?
Thanks!