ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   multiple sets words replace (https://www.excelbanter.com/new-users-excel/182762-multiple-sets-words-replace.html)

dk

multiple sets words replace
 
Is there anyway to make a listinng for find & Replace
ex;if=then
out=like
hello=go
we have about 100 different words that we want to replace with others
so we want to make a txt or other file of the full list & then run in excel
or word a 1 step find replace

Gary''s Student

multiple sets words replace
 
This is just an example. We have a worksheet called "xlator". The
translation table is in columns A & B. The text to be editted is in
"Sheet2". Enter and run the following macro:

Sub transla()
Dim inn() As String, outt() As String
Sheets("xlator").Activate
n = Cells(Rows.Count, 1).End(xlUp).Row
ReDim inn(1 To n), outt(1 To n)
For i = 1 To n
inn(i) = Cells(i, 1).Value
outt(i) = Cells(i, 2).Value
Next

Sheets("Sheet2").Activate
For Each r In ActiveSheet.UsedRange
v = r.Value
For i = 1 To n
v = Replace(v, inn(i), outt(i))
Next
r.Value = v
Next
End Sub

--
Gary''s Student - gsnu2007g


"dk" wrote:

Is there anyway to make a listinng for find & Replace
ex;if=then
out=like
hello=go
we have about 100 different words that we want to replace with others
so we want to make a txt or other file of the full list & then run in excel
or word a 1 step find replace


dk

multiple sets words replace
 
Can you please explain all steps
Thank You

"Gary''s Student" wrote:

This is just an example. We have a worksheet called "xlator". The
translation table is in columns A & B. The text to be editted is in
"Sheet2". Enter and run the following macro:

Sub transla()
Dim inn() As String, outt() As String
Sheets("xlator").Activate
n = Cells(Rows.Count, 1).End(xlUp).Row
ReDim inn(1 To n), outt(1 To n)
For i = 1 To n
inn(i) = Cells(i, 1).Value
outt(i) = Cells(i, 2).Value
Next

Sheets("Sheet2").Activate
For Each r In ActiveSheet.UsedRange
v = r.Value
For i = 1 To n
v = Replace(v, inn(i), outt(i))
Next
r.Value = v
Next
End Sub

--
Gary''s Student - gsnu2007g


"dk" wrote:

Is there anyway to make a listinng for find & Replace
ex;if=then
out=like
hello=go
we have about 100 different words that we want to replace with others
so we want to make a txt or other file of the full list & then run in excel
or word a 1 step find replace


Max

multiple sets words replace
 
Here's the easy steps to implement GS' subroutine suggestion ..
(Thought it was a good suggestion by GS, btw)

Install GS' sub into a regular module as below:
In your excel file:
1. Press Alt+F11 to go to VBE
In VBE, click Insert Module
Copy n paste GS' sub into the code window
(everything within the dotted lines from line: Sub transla() ... to the
line: End sub, as indicatively shown below. Go back to GS' response to do the
actual copying)

'----------
Sub transla()
....
End sub
'---------

Press Alt+Q to get back to Excel

2. In Excel,
a. Insert a new sheet, name it as: xlator
List the text that you want to find in col A, and the corresponding text to
replace it with in col B

b. Go to the sheet that you have the text to be found n replaced all at one
go. Rename the sheet as: Sheet2

Alternatively, you could go back to VBE and amend this line in the sub to
reflect your actual sheetname:

Sheets("Sheet2").Activate

c. Press Alt+F8 to bring up the Macro dialog
Either double-click directly on "transla" inside the window,
or select "transla", click Run, to run the sub.

Last but not least, do go back to GS' response and click the "Yes" button.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---

dk

multiple sets words replace
 
We are getting runtime error 13 error 2029

"Max" wrote:

Here's the easy steps to implement GS' subroutine suggestion ..
(Thought it was a good suggestion by GS, btw)

Install GS' sub into a regular module as below:
In your excel file:
1. Press Alt+F11 to go to VBE
In VBE, click Insert Module
Copy n paste GS' sub into the code window
(everything within the dotted lines from line: Sub transla() ... to the
line: End sub, as indicatively shown below. Go back to GS' response to do the
actual copying)

'----------
Sub transla()
...
End sub
'---------

Press Alt+Q to get back to Excel

2. In Excel,
a. Insert a new sheet, name it as: xlator
List the text that you want to find in col A, and the corresponding text to
replace it with in col B

b. Go to the sheet that you have the text to be found n replaced all at one
go. Rename the sheet as: Sheet2

Alternatively, you could go back to VBE and amend this line in the sub to
reflect your actual sheetname:

Sheets("Sheet2").Activate

c. Press Alt+F8 to bring up the Macro dialog
Either double-click directly on "transla" inside the window,
or select "transla", click Run, to run the sub.

Last but not least, do go back to GS' response and click the "Yes" button.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


Max

multiple sets words replace
 
I'm not sure what happened over there when you tried it out ..
(I don't know whether GS will come back here)

Here's my offer to you:
Download this sample file
It has GS' sub implemented & a set-up with dummy data
Try it out in Sheet2 (easy steps given):
http://www.freefilehosting.net/download/3f41e
Sub to Find n Replace.xls

--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com