(Solved) – VBA to replace the same letter with different values

(solved)-–-vba-to-replace-the-same-letter-with-different-values

I am trying to write vba code that will look up a letter in a string and replace it with a specific cell value.

Problem is that the letter may appear in the string a maximum of 3 times and each time the letter needs to be replaced by different value.

Example string I have x and x and x

The first x should be replaced with 1, second with 2 and third with 3.

My code so far

for i = 0 to lim

range("B" & lim  13).Value = replace (range("B" & lim  13), "x",range("K" & lim  13).Value)

Next i

The problem with above code is that this will replace each x with the same value; I would like to make it with a specific order of replacement.

Ideally the second and third replace would come from a different cell value of my choice.

Leave a Reply

Your email address will not be published. Required fields are marked *