Here is a solution that uses regular expressions, which is a much more powerful pattern matching tool than Like and InStr. It allows you to find out if a pattern is present, capture it, and switch it around. I did some testing to make sure the concept works but without your file and data I can't test this exact code.
Regex is a pattern matching language. I will break down the pattern I used:
^(.*)(Op\.[0-9]*)(.*)$
^ matches the beginning of the line. It ensures that the pattern must start at the beginning of the line.
(.*) The . means "match any character". The * means "match any number of the preceding character" so it will match any string of characters. The ( ) mean "save whatever matches this".
(Op\.[0-9]*) This says look for Op. (you have to use the \ to mean "look for an actual . instead of matching any character") followed by any number of digits. Save whatever matches this.
(.*)$ The $ means "end of string" so this will match all characters following your Op string to the end of the line. Save whatever matches this.
Now we have saved three strings: The beginning the string, the Op.xxx string, and the end of the string. We can use the $ variables to rearrange them. Each string we saved can be referenced in Replace as $1, $2, and $3. So we replace the above string with
$2, $1$3
$2 is the Op string, followed by the original beginning of the string, and then the original end of the string.
Bookmarks