在Excel中清除函数不起作用

我知道Excel CLEAN函数从所提供的文本string中删除所有不可打印的字符。例如让我们考虑下面的命令在Excel中

=CHAR(127)& "10" 

结果是

在这里输入图像描述

它位于A1的单元格,但命令

 =CLEAN(A1) 

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

来自Microsoft Office支持:CLEANfunction

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

我创build了一个function,可以删除select范围内的这些字符

 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 

因为我发现干净的function为以下命令工作

 =CHAR(21)& "dato" 

但char(21)和char(127)types不可打印字符,有什么区别?