|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 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 可以在单元格中使用。。。 |
|