Looping in Macro for replacing a few values


July 22nd, 2013 by Joanna Xu Joanna Xu

Hi Jason and team, i have a question on the how to write up a macro code that enable me to replace a few values.

For example, i would like to replace MAL as Malaysia / IND as Indonesia / CAM as Cambodia. Is there a way to loop and use IF condition?

What i think of is to read value of example cell A2, and loop with IF(read value=”MAL”,”Malaysia”,”"). Is it okay to have a few IF condition in the same loop?

One Response to “Looping in Macro for replacing a few values”

  1. admin admin Says:

    Hi Joanna,

    Yes, it is possible. They are called nested IF, similar to nested IF using Excel formula. The setup can be like this:

    IF read_value = “MAL” then
    ‘code to replace value with “Malaysia
    Else
    IF read_value = “IND” then
    ‘code to replace value with “Indonesia”
    Else
    ‘some thing else
    End IF
    End IF

Leave a Reply

You must be logged in to post a comment.

s2Member®