1

设置

我在 Excel 2012 中使用 VBA

问题

我需要搜索工作表并替换任何“#”。仅在第一列。第二个 Cells.Replace 不起作用。我认为这是因为“# # #”不喜欢那种类型的字符串。

当前代码

    '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

任何事情都会。

4

3 回答 3

1
'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
于 2013-08-07T21:02:50.060 回答
1

擦除 # 的任何组合

Cells.Replace "#", "", xlPart

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

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

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

于 2013-08-07T20:59:46.590 回答
0

看起来它应该工作。如果它没有按预期工作,请确保您指定了相同的字符串。看起来像空格字符的东西可能不是,所以要么使用 Excel 中的 mid & char 函数进行仔细检查,要么直接从您要查找的单元格之一进行剪切和粘贴。

于 2013-08-08T11:57:48.953 回答