PDA

View Full Version : Find Replace '?' (Question Mark) and '*' (Asterisk) Characters using VBA



ExcelBaap
08-02-2017, 09:44 PM
Generally, when you write a Find/Replace statement in VBA, it is difficult to replace '?' (Question Mark) and '*' (Asterisk) Symbols/Characters with anything else. It ends up replacing all the characters. The reason for this is that '?' and '*' are wild card characters. '?' stands for 1 character and '*' stands for n characters (where n is any positive integer).

The way to do this is to precede the character '?' or '*' with a tilde '~'. Here's a sample code (if you want to replace '?' or '*' with a blank):



Selection.Replace What:="~?", Replacement:=""
Selection.Replace What:="~*", Replacement:=""


Hope this helps!