#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-replace

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!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Macro-replace

Hi,

You don't need a macro for this you can simply do a search/replace but as
you asked for a macro, try this

Sub Sonic()
Dim RepString As Variant
Dim FindString As Variant
FindString = "Jim,John,Mary"
RepString = "Atlanta,Las Vegas,Chicago"
s = Split(FindString, ",")
t = Split(RepString, ",")
For x = 0 To UBound(s)
Cells.Replace What:=s(x), Replacement:=t(x), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next
End Sub

Mike

"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!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Macro-replace

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!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-replace

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!

"Mike H" wrote:

Hi,

You don't need a macro for this you can simply do a search/replace but as
you asked for a macro, try this

Sub Sonic()
Dim RepString As Variant
Dim FindString As Variant
FindString = "Jim,John,Mary"
RepString = "Atlanta,Las Vegas,Chicago"
s = Split(FindString, ",")
t = Split(RepString, ",")
For x = 0 To UBound(s)
Cells.Replace What:=s(x), Replacement:=t(x), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next
End Sub

Mike

"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!

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-replace

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!



  #6   Report Post  
Posted to microsoft.public.excel.misc
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!

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-replace

It's working. Thanks!
But i have so many entries i have to change, not just these three examples.
And it wiould become confusing. Can i do something like this?

arrFind = Array("Atlanta", "New York" , "Denver")
arrReplace = Array("Jim")

arrFind = Array("Las Vegas", "Detroit", "Washington ")
arrReplace = Array("John")

arrFind = Array("Chicago", "Ohio", "Los Angeles ")
arrReplace = Array("Mary")

And i need the macro to replace only in Column L range (L:L)
Can this be done?
Thanks!

"Jacob Skaria" wrote:

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!

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Macro-replace

Try the below..In the below example find and replace texts are mentioned in
Sheet3 in the same workbook and the range is A1:B10. Adjust to suit

Dim intTemp As Integer, arrFindReplace As Variant
arrFindReplace = Worksheets("Sheet3").Range("A1:B10")

For intTemp = 1 To UBound(arrFindReplace)
If Trim(arrFindReplace(intTemp, 1)) < "" Then
Cells.Replace What:=arrFindReplace(intTemp, 1), _
Replacement:= arrFindReplace(intTemp, 2), _
LookAt:=xlWhole, SearchOrder:=xlByRows
End If
Next

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


"puiuluipui" wrote:

It's working. Thanks!
But i have so many entries i have to change, not just these three examples.
And it wiould become confusing. Can i do something like this?

arrFind = Array("Atlanta", "New York" , "Denver")
arrReplace = Array("Jim")

arrFind = Array("Las Vegas", "Detroit", "Washington ")
arrReplace = Array("John")

arrFind = Array("Chicago", "Ohio", "Los Angeles ")
arrReplace = Array("Mary")

And i need the macro to replace only in Column L range (L:L)
Can this be done?
Thanks!

"Jacob Skaria" wrote:

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!

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-replace

This is better than everything. Thanks allot!
The problem is that the macro is changing everything in sheet1 (active
sheet). I need this last code, but to change text only in L column (L:L).
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Try the below..In the below example find and replace texts are mentioned in
Sheet3 in the same workbook and the range is A1:B10. Adjust to suit

Dim intTemp As Integer, arrFindReplace As Variant
arrFindReplace = Worksheets("Sheet3").Range("A1:B10")

For intTemp = 1 To UBound(arrFindReplace)
If Trim(arrFindReplace(intTemp, 1)) < "" Then
Cells.Replace What:=arrFindReplace(intTemp, 1), _
Replacement:= arrFindReplace(intTemp, 2), _
LookAt:=xlWhole, SearchOrder:=xlByRows
End If
Next

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


"puiuluipui" wrote:

It's working. Thanks!
But i have so many entries i have to change, not just these three examples.
And it wiould become confusing. Can i do something like this?

arrFind = Array("Atlanta", "New York" , "Denver")
arrReplace = Array("Jim")

arrFind = Array("Las Vegas", "Detroit", "Washington ")
arrReplace = Array("John")

arrFind = Array("Chicago", "Ohio", "Los Angeles ")
arrReplace = Array("Mary")

And i need the macro to replace only in Column L range (L:L)
Can this be done?
Thanks!

"Jacob Skaria" wrote:

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!

  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Macro-replace

Replace
Cells.Replace
with
Columns("L").Replace

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


"puiuluipui" wrote:

This is better than everything. Thanks allot!
The problem is that the macro is changing everything in sheet1 (active
sheet). I need this last code, but to change text only in L column (L:L).
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Try the below..In the below example find and replace texts are mentioned in
Sheet3 in the same workbook and the range is A1:B10. Adjust to suit

Dim intTemp As Integer, arrFindReplace As Variant
arrFindReplace = Worksheets("Sheet3").Range("A1:B10")

For intTemp = 1 To UBound(arrFindReplace)
If Trim(arrFindReplace(intTemp, 1)) < "" Then
Cells.Replace What:=arrFindReplace(intTemp, 1), _
Replacement:= arrFindReplace(intTemp, 2), _
LookAt:=xlWhole, SearchOrder:=xlByRows
End If
Next

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


"puiuluipui" wrote:

It's working. Thanks!
But i have so many entries i have to change, not just these three examples.
And it wiould become confusing. Can i do something like this?

arrFind = Array("Atlanta", "New York" , "Denver")
arrReplace = Array("Jim")

arrFind = Array("Las Vegas", "Detroit", "Washington ")
arrReplace = Array("John")

arrFind = Array("Chicago", "Ohio", "Los Angeles ")
arrReplace = Array("Mary")

And i need the macro to replace only in Column L range (L:L)
Can this be done?
Thanks!

"Jacob Skaria" wrote:

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!



  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-replace

It's perfect. Perfect!
Thanks allot!

"Jacob Skaria" wrote:

Replace
Cells.Replace
with
Columns("L").Replace

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


"puiuluipui" wrote:

This is better than everything. Thanks allot!
The problem is that the macro is changing everything in sheet1 (active
sheet). I need this last code, but to change text only in L column (L:L).
Can this be done?
Thanks!

"Jacob Skaria" wrote:

Try the below..In the below example find and replace texts are mentioned in
Sheet3 in the same workbook and the range is A1:B10. Adjust to suit

Dim intTemp As Integer, arrFindReplace As Variant
arrFindReplace = Worksheets("Sheet3").Range("A1:B10")

For intTemp = 1 To UBound(arrFindReplace)
If Trim(arrFindReplace(intTemp, 1)) < "" Then
Cells.Replace What:=arrFindReplace(intTemp, 1), _
Replacement:= arrFindReplace(intTemp, 2), _
LookAt:=xlWhole, SearchOrder:=xlByRows
End If
Next

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


"puiuluipui" wrote:

It's working. Thanks!
But i have so many entries i have to change, not just these three examples.
And it wiould become confusing. Can i do something like this?

arrFind = Array("Atlanta", "New York" , "Denver")
arrReplace = Array("Jim")

arrFind = Array("Las Vegas", "Detroit", "Washington ")
arrReplace = Array("John")

arrFind = Array("Chicago", "Ohio", "Los Angeles ")
arrReplace = Array("Mary")

And i need the macro to replace only in Column L range (L:L)
Can this be done?
Thanks!

"Jacob Skaria" wrote:

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!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Macro Sandy Mann Excel Discussion (Misc queries) 8 December 5th 07 03:05 PM
Replace Vlookup with a macro Arain Excel Discussion (Misc queries) 1 September 27th 06 09:32 AM
Macro to Find & Replace [email protected] Excel Worksheet Functions 2 September 14th 06 07:17 PM
replace macro? andrewm Excel Worksheet Functions 1 October 19th 05 12:47 PM
Find & Replace in VB macro JackC Excel Discussion (Misc queries) 1 August 24th 05 09:22 PM


All times are GMT +1. The time now is 11:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"