2

トリム機能はスペースのみをトリムします。すべての非印刷文字をトリミングする関数が必要です。

私のコード...

Private Sub CleanUpData()
    LastRow = Application.CountA(ActiveSheet.Range("A:A"))
    For CurrentRow = 2 To LastRow
        Cells(CurrentRow, 1) = Trim(Cells(CurrentRow, 1))
        Cells(CurrentRow, 2) = Trim(Cells(CurrentRow, 2))
        Cells(CurrentRow, 3) = Trim(Cells(CurrentRow, 3))
        Cells(CurrentRow, 4) = Trim(Cells(CurrentRow, 4))
    Next CurrentRow
End Sub

...何もしません。

4

2 に答える 2

2

これを試して:

 Public Function TrimComplete(ByVal sValue As String) As _
        String

        Dim sAns As String
        Dim sWkg As String
        Dim sChar As String
        Dim lLen As Long
        Dim lCtr As Long

        sAns = sValue
        lLen = Len(sValue)

        If lLen > 0 Then
            'Ltrim
            For lCtr = 1 To lLen
                sChar = Mid(sAns, lCtr, 1)
                If (Asc(sChar) > 32) and (Asc(sChar) < 127) Then Exit For
            Next

            sAns = Mid(sAns, lCtr)
            lLen = Len(sAns)

            'Rtrim
            If lLen > 0 Then
                For lCtr = lLen To 1 Step -1
                    sChar = Mid(sAns, lCtr, 1)
                    If (Asc(sChar) > 32) and (Asc(sChar) < 127) Then Exit For
                Next
            End If
            sAns = Left$(sAns, lCtr)
        End If

        TrimComplete = sAns

    End Function

から撮影

ソースへのリンク

于 2011-03-09T18:43:33.203 に答える