excel中的清除功能不起作用 我知道Excel清除函数从提供的文本字符串中删除所有不可打印的字符。例如,让我们考虑Excel 中的以下命令 =CHAR(127)& "10"

excel中的清除功能不起作用 我知道Excel清除函数从提供的文本字符串中删除所有不可打印的字符。例如,让我们考虑Excel 中的以下命令 =CHAR(127)& "10",excel,Excel,结果是 它位于A1单元,但命令 =CLEAN(A1) 会留下相同的结果,那么问题是什么呢?为什么它不工作因为我发现clean函数适用于以下命令 =CHAR(21)& "dato" 但是char21和char127输入相同的不可打印字符,有什么区别吗?因为我发现clean函数适用于以下命令 =CHAR(21)& "dato" 但char21和char127输入相同的不可打印字符,有什么区别 CLEAN函数用于从文本中删除7位ASCII码值0到31中的前32个非打印字符。在Un

结果是

它位于A1单元,但命令

=CLEAN(A1)

会留下相同的结果,那么问题是什么呢?为什么它不工作

因为我发现clean函数适用于以下命令

=CHAR(21)& "dato"

但是char21和char127输入相同的不可打印字符,有什么区别吗?

因为我发现clean函数适用于以下命令

=CHAR(21)& "dato"
但char21和char127输入相同的不可打印字符,有什么区别

CLEAN函数用于从文本中删除7位ASCII码值0到31中的前32个非打印字符。在Unicode字符集中,还有其他非打印字符值127、129、141、143、144和157。CLEAN函数本身不会删除这些额外的非打印字符


CLEAN函数用于从文本中删除7位ASCII码值0到31中的前32个非打印字符。在Unicode字符集中,还有其他非打印字符值127、129、141、143、144和157。CLEAN函数本身不会删除这些额外的非打印字符

我创建了一个函数,可以删除选择范围内的这些字符

Sub Remove_Invisible_Character()
'Remove spaces and nonprinting characters from text

'9,13,28,29,30,31,128,129,130,131,132,133,134,135,136,137,
'138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,
'153,154,155,156,157,158,159,1970,1971,1972,1973,1974,1975,1976,
'1977,1978,1979,1980,1981,1982,1983,6155,6156,6157,6158,8203,8204,
'8205,8206,8207,8233,8234,8235,8236,8237,8238,8289,8290,8291,8292,
'8298,8299,8300,8301,8302,8303,64976,64977,64978,64979,64980,64981,
'64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,
'64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,
'65004,65005,65006,65007,65060,65061,65062,65063,65064,65065,65066,
'65067,65068,65069,65070,65071,65279


Dim C, nArrSearch As Variant
Dim nRng As Range
Dim firstAddress, nMsg, nChar As String
Dim bRemoved As Boolean
Dim N As Single
Dim nSearchStr As Variant

nChar = ""
nChar = nChar & "9,13,28,29,30,31,128,129,130,131,132,133,134,135,136,137,"
nChar = nChar & "138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,"
nChar = nChar & "153,154,155,156,157,158,159,1970,1971,1972,1973,1974,1975,1976,"
nChar = nChar & "1977,1978,1979,1980,1981,1982,1983,6155,6156,6157,6158,8203,8204,"
nChar = nChar & "8205,8206,8207,8233,8234,8235,8236,8237,8238,8289,8290,8291,8292,"
nChar = nChar & "8298,8299,8300,8301,8302,8303,64976,64977,64978,64979,64980,64981,"
nChar = nChar & "64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,"
nChar = nChar & "64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,"
nChar = nChar & "65004,65005,65006,65007,65060,65061,65062,65063,65064,65065,65066,"
nChar = nChar & "65067,65068,65069,65070,65071,65279"

nArrSearch = Split(nChar, ",")

With Selection

    For N = 0 To UBound(nArrSearch)
        nSearchStr = ChrW(CSng(nArrSearch(N)))
        nSearchStr = "*" & nSearchStr & "*"
        Set C = .Find(nSearchStr, LookIn:=xlFormulas)
        If Not C Is Nothing Then
            If nRng Is Nothing Then
                Set nRng = C
            Else
                Set nRng = Union(nRng, C)
            End If
            firstAddress = C.Address(0, 0)
            Do While Not C Is Nothing
                Set C = .FindNext(C)
                If C.Address(0, 0) = firstAddress Then Exit Do

                Set nRng = Union(nRng, C)
            Loop
        End If
    Next N
End With
    If Not nRng Is Nothing Then
        nMsg = "Based on Your Selection : " & Selection.Address(0, 0) & vbNewLine & _
                "Total Found : " & nRng.Cells.Count & vbNewLine

        If MsgBox(nMsg & vbNewLine & _
                "Do you want to remove invisible character ?", vbYesNo + vbQuestion, "Remove Invisible Character") <> vbYes Then Exit Sub

        bRemoved = True
        For N = 0 To UBound(nArrSearch)
            nSearchStr = ChrW(CSng(nArrSearch(N)))
            'MsgBox AscB(nSearchStr)
           ' MsgBox nRng.Replace(Asc(CSng(nArrSearch(N))), "", MatchByte:=True)
            If nRng.Replace(nSearchStr, "", MatchByte:=True) <> True Then
                bRemoved = False
            End If
        Next N

        If bRemoved Then
            MsgBox "Invisible Character Removed", , "Completed"
        Else
            MsgBox "Some invisible character not able to remove" & vbNewLine & _
                    "Please inform the Developer for further improvement", , "Completed"
        End If
    Else
        MsgBox "Based on Your Selection : " & Selection.Address(0, 0) & vbNewLine & _
                "No Invisible Character Found", vbInformation

    End If

End Sub

我创建了一个函数,可以删除这些字符的选择范围

Sub Remove_Invisible_Character()
'Remove spaces and nonprinting characters from text

'9,13,28,29,30,31,128,129,130,131,132,133,134,135,136,137,
'138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,
'153,154,155,156,157,158,159,1970,1971,1972,1973,1974,1975,1976,
'1977,1978,1979,1980,1981,1982,1983,6155,6156,6157,6158,8203,8204,
'8205,8206,8207,8233,8234,8235,8236,8237,8238,8289,8290,8291,8292,
'8298,8299,8300,8301,8302,8303,64976,64977,64978,64979,64980,64981,
'64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,
'64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,
'65004,65005,65006,65007,65060,65061,65062,65063,65064,65065,65066,
'65067,65068,65069,65070,65071,65279


Dim C, nArrSearch As Variant
Dim nRng As Range
Dim firstAddress, nMsg, nChar As String
Dim bRemoved As Boolean
Dim N As Single
Dim nSearchStr As Variant

nChar = ""
nChar = nChar & "9,13,28,29,30,31,128,129,130,131,132,133,134,135,136,137,"
nChar = nChar & "138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,"
nChar = nChar & "153,154,155,156,157,158,159,1970,1971,1972,1973,1974,1975,1976,"
nChar = nChar & "1977,1978,1979,1980,1981,1982,1983,6155,6156,6157,6158,8203,8204,"
nChar = nChar & "8205,8206,8207,8233,8234,8235,8236,8237,8238,8289,8290,8291,8292,"
nChar = nChar & "8298,8299,8300,8301,8302,8303,64976,64977,64978,64979,64980,64981,"
nChar = nChar & "64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,"
nChar = nChar & "64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,"
nChar = nChar & "65004,65005,65006,65007,65060,65061,65062,65063,65064,65065,65066,"
nChar = nChar & "65067,65068,65069,65070,65071,65279"

nArrSearch = Split(nChar, ",")

With Selection

    For N = 0 To UBound(nArrSearch)
        nSearchStr = ChrW(CSng(nArrSearch(N)))
        nSearchStr = "*" & nSearchStr & "*"
        Set C = .Find(nSearchStr, LookIn:=xlFormulas)
        If Not C Is Nothing Then
            If nRng Is Nothing Then
                Set nRng = C
            Else
                Set nRng = Union(nRng, C)
            End If
            firstAddress = C.Address(0, 0)
            Do While Not C Is Nothing
                Set C = .FindNext(C)
                If C.Address(0, 0) = firstAddress Then Exit Do

                Set nRng = Union(nRng, C)
            Loop
        End If
    Next N
End With
    If Not nRng Is Nothing Then
        nMsg = "Based on Your Selection : " & Selection.Address(0, 0) & vbNewLine & _
                "Total Found : " & nRng.Cells.Count & vbNewLine

        If MsgBox(nMsg & vbNewLine & _
                "Do you want to remove invisible character ?", vbYesNo + vbQuestion, "Remove Invisible Character") <> vbYes Then Exit Sub

        bRemoved = True
        For N = 0 To UBound(nArrSearch)
            nSearchStr = ChrW(CSng(nArrSearch(N)))
            'MsgBox AscB(nSearchStr)
           ' MsgBox nRng.Replace(Asc(CSng(nArrSearch(N))), "", MatchByte:=True)
            If nRng.Replace(nSearchStr, "", MatchByte:=True) <> True Then
                bRemoved = False
            End If
        Next N

        If bRemoved Then
            MsgBox "Invisible Character Removed", , "Completed"
        Else
            MsgBox "Some invisible character not able to remove" & vbNewLine & _
                    "Please inform the Developer for further improvement", , "Completed"
        End If
    Else
        MsgBox "Based on Your Selection : " & Selection.Address(0, 0) & vbNewLine & _
                "No Invisible Character Found", vbInformation

    End If

End Sub

也许你可以用=SUBSTITUTEA1,CHAR127,“,代替?是的,我知道我用过这个,很奇怪也许你可以用=SUBSTITUTEA1,CHAR127,”,代替?是的,我知道我用过这个,很奇怪,显然,这些字符不一样。只是excel显示了一个?在一个框中输入更多不能表示为字符的字符。例如,控制。您将在尝试char27、char25等时看到相同的结果。显然,这些字符不相同。只是excel显示了一个?在一个框中输入更多不能表示为字符的字符。例如,控制。您将在尝试char27、char25等时看到相同的结果