Consulting

Results 1 to 2 of 2

Thread: using Excel function TRIM rather than VBA function TRIM

  1. #1

    using Excel function TRIM rather than VBA function TRIM

    Hi,

    In the picture below, column d is the result I want.

    In my code below, I can't produce the result I want, because VBA f TRIM is not same as Excel f TRIM.

    Could you please amend my code so that I can produce the result I want?


    [VBA]
    Sub Remove_Excess_Space_()

    For Each x In Selection

    i = x.Row
    x.Offset(0, 2) = Trim(Cells(i, 2).Value)

    Next

    End Sub
    [/VBA]


    Thanks
    Attached Images Attached Images
    • File Type: jpg l.jpg (19.5 KB, 37 views)

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Remove_Excess_Space_()

    For Each x In Selection

    i = x.Row
    x.Offset(0, 2) = Application.Trim(Cells(i, 2).Value)

    Next

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •