Consulting

Results 1 to 6 of 6

Thread: Problem in replacing macro

  1. #1

    Problem in replacing macro

    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?

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Show your existing code and we'll probably be able to tweak it.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Don't use single criteria in your code, otherwise it will simply replace N with R.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    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
    Attached Files Attached Files

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    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?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    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 !!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •