Trim Sel di Excel

Ini makro untuk menjalankan program trim di sel yang terpilih di excel.

Option Explicit
Sub DoTrim()
    Dim cell As Range
    Dim str As String
    Dim nAscii As Integer
    For Each cell In Selection.Cells
        If cell.HasFormula = False Then
            str = Trim(CStr(cell))
            If Len(str) > 0 Then
                nAscii = Asc(Left(str, 1))
                If nAscii  1 Then
                        str = Right(str, Len(str) - 1)
                    Else
                        str = ""
                    End If
                End If
            End If
            cell=str
        End If
    Next
End Sub

Dengan menjalankan potongan kode macro ini akan menyebabkan semua karakter spasi sebelum dan sesudah data pada sel terpilih akan terhapus.

http://stackoverflow.com/questions/2964769/trim-cells-using-vba-in-excel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s