Search and Replace Minus First Character

B

Bad at VBA

I know this should be easy, but I'm not getting anyplace with it.

What I want to do is search for all occurances of procedure numbers in
my document, which have a pattern of P####, and just remove the "P" so
the original number is all that's left.

So P1234 becomes 1234
P5326 becomes 5326
etc.

Any tips or help would be greatly appreciated!
 
K

Klaus Linke

So P1234 becomes 1234
P5326 becomes 5326
etc.



No VBA needed: You should be able to create the code with the macro recorder
and a wildcard replacement.
Edit > Replace, check "More > Match wildcards",
Find what: P([0-9]{4})
Replace with: \1

P matches P, [0-9] matches any number from 0 to 9, {4} matches 4 of the
previous expression (= 4 numbers).
You can put (parentheses) around a wildcard expression if you want to reuse
it.
In "Replace with", you use \1 for the first such expression (...in this case
the only one).

Regards,
Klaus
 
B

Bad at VBA

But, but that's way too easy!

Thank you so much Klaus.

So P1234 becomes 1234
P5326 becomes 5326
etc.

No VBA needed: You should be able to create the code with the macro recorder
and a wildcard replacement.
Edit > Replace, check "More > Match wildcards",
Find what: P([0-9]{4})
Replace with: \1

P matches P, [0-9] matches any number from 0 to 9, {4} matches 4 of the
previous expression (= 4 numbers).
You can put (parentheses) around a wildcard expression if you want to reuse
it.
In "Replace with", you use \1 for the first such expression (...in this case
the only one).

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top