PDA

View Full Version : Problem in replacing macro



jignesh142
07-16-2013, 01:11 AM
Dear Friends,

I have created the macro for replacing the one word with another word. for example "N" with "S" and "S" with "R" etc (which is present in the sheet)
This replace value is taken from the table
what my problem is when macro executes it replace the "N" with "S" and again then "S" with "R" so, ultimately it replaces "N" with "R", which i want to avoid
if once it is replaced then i want to avoid replacing second time

How can i do this?

p45cal
07-16-2013, 02:34 AM
Show your existing code and we'll probably be able to tweak it.

Aussiebear
07-16-2013, 04:23 AM
Don't use single criteria in your code, otherwise it will simply replace N with R.

jignesh142
07-18-2013, 10:40 PM
Please find the attched sheet in which the macro is recorded. please run the macro to see the result.
Please see that all the letters are ultimately replaced by "G", instead of the matching letters which is shown in table

p45cal
07-19-2013, 12:35 AM
One way (though it may not always be possible (it is possible in your example)) is to make sure that the order in which you do the replacing is such that you never try to look for something that you have already replaced. So instead of this order:
N becomes S
S becomes R
R become G
use this order:
R become G
S becomes R
N becomes S

(No word in the left column is to be found in any of the rows above it in the right column.)

In your example sheet you should leave the code the same, but change the order in J8:K12.

So your original:
NS RR SS mm
which originally became:
GG GG GG mm
now becomes:
SR GG RR mm

Is that your intended result?

jignesh142
07-19-2013, 01:50 AM
Hi p45cal

Thai is the same which i wanted, Which indicates me to run the loop in the reverse direction, i.e., last latter to change first.

Simple and helpful solution

Thanks !!!!