2015-12-06 24 views
2

我知道,Excel的CLEAN函数从string.for实例中提供的文本的所有非打印字符,让我们在Excel中考虑以下命令明确功能不起作用

=CHAR(127)& "10" 

结果是

enter image description here

它位于在A1细胞,但命令

=CLEAN(A1) 

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

+0

也许你可以使用= SUBSTITUTE(A1,CHAR(127)的功能,” “),而不是? – tagoma

+0

是的,我知道这个我只用了它很好奇 –

回答

-1

因为我发现清洁功能如下命令

=CHAR(21)& "dato" 

但CHAR(21)和焦炭(127)型相同的非打印字符的工作,是有什么区别?

+0

显然,那些不是一样的字符,只是excel在一个盒子里显示了更多字符,不能表示为字符。例如controls。在尝试char(27),char(25)等时会看到相同的结果 – PankajR

0

from Microsoft Office Support: CLEAN Function

CLEAN函数被设计从文本在7位ASCII码,以除去所述第一32不可打印的字符(值从0到31)。在Unicode字符集中,还有其他非打印字符(值127,129,141,143,144和157)。就其本身而言,清洁功能不会删除这些额外的非打印字符

0

我创建了一个可以在选择范围中删除这些字符

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