VBA Cells.Replace()

build立

我在Excel 2012中使用VBA

我需要search一张表并replace任何“#”。 只在第一列。 第二个Cells.Replace不起作用。 我认为这是因为“###”不喜欢这种types的string。

当前代码

'Find and replace "#" with "" Cells.Replace What:="###", Replacement:="", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False Cells.Replace What:="# # #", Replacement:="", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False 

任何事情都会。

擦除#的任何组合

 Cells.Replace "#", "", xlPart 

**擦除###或####或##**

 Cells.Replace "###", "", xlPart Cells.Replace "## # #", "", xlPart Cells.Replace "# # #", "", xlPart 

编辑:评论解释需要删除###或####或###。

 'Find and replace "#" with "" in the first column only Columns(1).Cells.Replace What:="#", Replacement:="", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False 

它看起来应该工作。 如果它没有按预期工作,请确保您指定了相同的string。 什么看起来像空格字符可能不是这样或者使用Excel中的中间和字符函数来仔细检查或直接从您正在寻找的单元格中剪切和粘贴。