|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 xiaocake 于 2020-12-2 14:52 编辑
- Option Explicit
- Sub aa()
- Dim sht As Worksheet
- Set sht = ActiveWorkbook.ActiveSheet
- Dim rngs
- Dim rng As Range
- Dim Arr, ar
- Dim c As Long, r As Long
- Set rngs = sht.UsedRange
- For Each rng In rngs
- rng = CleanStr(rng.Text)
- Next
- End Sub
- Function CleanStr(ByVal str As String) As String
- Dim Tstr As String
- Dim I As Long
- Dim txt As String
- Dim cc As String
- Tstr = Trim(str)
- If Len(Tstr) > 0 Then
- For I = 1 To Len(Tstr)
- cc = Mid(Tstr, I, 1)
- If Asc(cc) <> 63 And Asc(cc) <> 9 And AscW(cc) <> 160 Then
- txt = txt & cc
- End If
- Next
- txt = Trim(txt)
- txt = WorksheetFunction.Clean(txt)
- CleanStr = txt
- Else
- CleanStr = str
- End If
- End Function
复制代码
试试我写的,笨方法,CleanStr 可以在单元格中使用。。。 |
|