|
楼主 |
发表于 2009-7-15 17:43
|
显示全部楼层
'撰写:老朽
'网址:http://Club.ExcelHome.net
'日期:2009-7-15 下午 05:41:43
Private Sub COMMANDBUTTON1_CLICK()
If Not (CheckBox1 Or CheckBox2) Then Exit Sub
Dim Ans, M, A, B, C, N
Ans = IIf(Me.Tag = "", 1, Me.Tag)
Application.ScreenUpdating = False
Dim I As Long , J As Long , Arr, T As Single ', Ans
T = Timer
If CheckBox1 Then '单纯空格
Select Case Ans
Case 1 '剔除全部空格
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart
Case 2 '剔除左边空格
Arr = Selection
For I = 1 To UBound (Arr, 1)
For J = 1 To UBound (Arr, 2)
Arr(I, J) = LTrim(Arr(I, J))
Next
Next
Selection = Arr
Case 3 '剔除右边空格
Arr = Selection
For I = 1 To UBound (Arr, 1)
For J = 1 To UBound (Arr, 2)
Arr(I, J) = RTrim(Arr(I, J))
Next
Next
Selection = Arr
Case 4 '同时剔除两边空格。
Arr = Selection
For I = 1 To UBound (Arr, 1)
For J = 1 To UBound (Arr, 2)
Arr(I, J) = Trim(Arr(I, J))
Next
Next
Selection = Arr
Case 5 '剔除中间空格,保留两端空格
Arr = Selection
For I = 1 To UBound (Arr, 1)
For J = 1 To UBound (Arr, 2)
Arr(I, J) = Replace(Arr(I, J), Trim(Arr(I, J)), Replace(Trim(Arr(I, J)), " ", ""))
Next
Next
Selection = Arr
End Select
End If
If CheckBox2 Then '剔除不可见字符
Dim Brr, Dic As New Dictionary
Brr = Array(7, 8, 9, 10, 13, 28, 29, 30, 31) '
For M = 0 To UBound (Brr): Dic(Chr(Brr(M))) = "": Next
If Ans = 1 Then '剔除全部不可见字符
Selection = Application.Clean(Selection)
Else
Select Case Ans
Case 2 '剔除左边不可见字符
Arr = Selection
For I = 1 To UBound (Arr, 1)
For J = 1 To UBound (Arr, 2)
For M = 1 To Len(Arr(I, J))
If Not Dic.Exists(Mid(Arr(I, J), M, 1)) Then Exit For
Next
Arr(I, J) = Mid(Arr(I, J), M)
Next
Next
Selection = Arr
Case 3 '剔除右边不可见字符
|
|