VBA 替换不适用于数字格式

VBA Replace not working with numbers format

我又一次陷入困境。

我正在尝试清理 phone 数字数据,但代码没有执行任何操作。

    Columns(icount).Replace What:=",", Replacement:="", LookAt:=xlWhole, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False


    Columns(icount).Replace What:="-", Replacement:="", LookAt:=xlWhole, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

icount 是 phone # 所在的列。

我不明白为什么它不起作用。将“à”替换为“à”效果很好。

尝试使用 'LookAt:=xlPart' 而不是 'LookAt:=xlWhole'

Columns(icount).Replace What:=",", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False


Columns(icount).Replace What:="-", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

你可以这样:

Sub rep()


For Each c In Sheets("Sheet1").Range("A:A").Cells ' Change the range that you want

    If InStr(c.Value, ",") > 0 Then
        deli = Split(c, "")
        For a = 0 To UBound(deli)
        c.Value = replace(c.Value, ",", "")
        Next a

    End If

    If InStr(c.Value, "-") > 0 Then
        deli = Split(c, "")
        For a = 0 To UBound(deli)
        c.Value = replace(c.Value, "-", "")
        Next a

    End If

Next c

End Sub