简体   繁体   English

Excel vba删除“?” (问号)和“*”(星号)

[英]Excel vba to remove “?” (question mark) and “*” (star)

I am trying to replace all special characters in an Excel sheet.我正在尝试替换 Excel 工作表中的所有特殊字符。

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 .... 等等

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这是一个有用的链接: https : //support.microsoft.com/en-gb/kb/214138

Use regular expressions: http://analystcave.com/excel-regex-tutorial/使用正则表达式: http : //analystcave.com/excel-regex-tutorial/

It's a much more versatile way to do text-matching anyway.无论如何,这是一种更通用的文本匹配方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM