+ Reply to Thread
Results 1 to 5 of 5

VBA code to trim spaces and tab from blank cells

Hybrid View

  1. #1
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: VBA code to trim spaces and tab from blank cells

    Dim Ccell As Range
    
    For Each Ccell In Range(Cells(1, 1), Cells(1, 1).SpecialCells(xlCellTypeLastCell))
      Ccell = Trim(Ccell)
    Next
    or

    Dim Ccell As Range
    
    For Each Ccell In Cells(1, 1).SpecialCells(xlCellTypeConstants, 23)
      Ccell = Trim(Ccell)
    Next
    Last edited by rwgrietveld; 02-11-2010 at 06:47 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA code to trim spaces and tab from blank cells

    Ricardo, FWIW using either of:

    Application.Transpose / Application.WorksheetFunction.Transpose

    is generally preferable than using VBA Trim because the VBA equiv. does not remove superfluous spaces mid string unlike the native version.

    To illustrate (via Immediate Window in VBE):

    ?Trim("Apples   Oranges")
    
    ?Application.Trim("Apples   Oranges")

    In this instance the cells contain only blank spaces then obviously the VBA Trim would suffice but the above is just worth bearing in mind in general terms...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1