Excel 365 我想修剪多余的字符和 ASCII 160。在数据列中

问题描述 投票:0回答:1

我找到了一个可以在单元格上使用的宏。我希望它能在 75000 行的列上工作。

Sub test() 
    Dim a$, b$, c$, i As Integer 
    a$ = Range("A1").Value 
    For i = 1 To Len(a$) 
        b$ = Mid(a$, i, 1) 
        If b$ Like "[A-Z,a-z,0-9]" Then 
            c$ = c$ & b$ 
        End If 
    Next i 
    Range("A2").Value = c$ 
End Sub
excel vba character trim
1个回答
0
投票

如果您知道需要替换的字符集。您可以使用Excel替换方法。

Sub Macro1()
    Dim aKey: aKey = Array(Chr(160), Chr(10)) ' expand as needed
    Dim i As Long
    For i = 0 To UBound(aKey)
        Columns("A:A").Replace What:="REWORK", Replacement:=aKey(i), LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Next
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.