Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel vba to remove "?" (question mark) and "*" (star)

Tags:

excel

vba

I am trying to replace all special characters in an Excel sheet.

But ? (question mark) and * (asterisk) are resulting in a blank cell

The code I'm using:

Selection.Replace What:="!", Replacement:=" "
Selection.Replace What:="@", Replacement:=" "
Selection.Replace What:="#", Replacement:=" "

.... so on

like image 888
jatin verma Avatar asked Oct 30 '25 14:10

jatin verma


1 Answers

Question marks and asterisks are known as wildcards in find and replace functions, this means they already mean something other than their string values. In order to get round this you need to precede them with a tilde (~).

Try:

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

Here's a helpful link: https://support.microsoft.com/en-gb/kb/214138

like image 167
Jordan Avatar answered Nov 01 '25 12:11

Jordan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!