+ Reply to Thread
Results 1 to 5 of 5

VBA code to trim spaces and tab from blank cells

  1. #1
    Registered User
    Join Date
    06-25-2009
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    76

    VBA code to trim spaces and tab from blank cells

    I have cells with no data but simply blank spaces or tabs. I want to delete the spaces/tabs from such cells

  2. #2
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

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

    Select all the cells & run this code:

    Please Login or Register  to view this content.

    This would remove all terminal & extra spaces & non-printable characters.

    Alternatively, you can also select all cells, do a Ctrl + H & replace space with nothing.

    Regards,
    Karan
    Last edited by karan; 02-11-2010 at 04:06 AM.

  3. #3
    Registered User
    Join Date
    06-25-2009
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    76

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

    hi, instead of selection can you please modify it so that it trims blanks spaces and tabs from sheet irrespective of selection

  4. #4
    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

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    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

  5. #5
    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):

    Please Login or Register  to view this content.

    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