Replace function with wildcard

2.2k Views Asked by At

Currently I have developed an operation tool which compares complex engineering source files of a DCS. Therefore I have to replace certain 'TagNames'.

The code where the replacing applies:

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With

An example would be tmp_string = 200TT-50 or 200TX-50 or 200GG-50

This should be transititioned to 350TT-50 or 350TX-50 or 350GG-50

So right now I would add the transitions 200TT --> 350TT 200TX --> 350tx

But what I would prefer is to appy this transition 200$$ --> 350$$

$ would mean a character [A-Z] So that when it gets applied it will directly apply all the transitions I mentioned above.

Wildcard does not work with Replace function.. Who has a clue? Because I will fill in different transitions all the time. So Regex doesn't seem like a solution to me.

Thanks in advance,

1

There are 1 best solutions below

1
On

You can use VBA.Left() like in

If VBA.Left(tmp_string, 3) = "200" then 
    tmp_string = "350" & VBA.Right(tmp_string, Len(tmp_string)-3)
end if