Consulting

Results 1 to 10 of 10

Thread: Solved: Deleteing indertiminate spaces

  1. #1

    Solved: Deleteing indertiminate spaces

    I have in column A file names, eg

    Joe Bloggs_Learning_Team <spaces end here
    Sam Smith_Artist_Patch <spaces end here
    Zen Hen_Clouring_Group <space end here

    The file names have interiminate white space at the end of them how can I get rid of it?

  2. #2
    I have also found out that the data base which gives me this data, is set to allow upto 60 charachters for the file name, if they dont get filled then it automatically leaves the blank spaces

  3. #3
    VBAX Regular JONvdHeyden's Avatar
    Joined
    Mar 2009
    Location
    Hampshire, UK
    Posts
    75
    Location
    You could try the TRIM function:

    =TRIM(A1)
    Regards,
    Jon von der Heyden (Excel 2003, OS XP Pro)

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Probably not the best idea, but if it's something that TRIM or Trim or Replace does not take care of, a quick/easy check that may be fruitful is to check an see if you can return the cahracter code. With the string planted in A1...

    =CODE(RIGHT(A1,1))

    Mark

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    There are a couple of KB items that relate to this. KBSearch
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I use a user function that (so far) cleans all the funny characters, and extra spaces


    [vba]
    'Ref: MS Excel 2007 Help, Remove spaces and nonprinting characters from text
    Function SuperClean(s As String) As String
    Dim s1 As String

    With Application.WorksheetFunction

    'non-printable characters NOT caught by CLEAN
    s1 = .Substitute(s, Chr(160), Chr(32)) ' non-breaking space
    s1 = .Substitute(s1, Chr(127), Chr(7)) ' ASCII 7 = BEL char
    s1 = .Substitute(s1, Chr(129), Chr(7))
    s1 = .Substitute(s1, Chr(141), Chr(7))
    s1 = .Substitute(s1, Chr(143), Chr(7))
    s1 = .Substitute(s1, Chr(144), Chr(7))
    s1 = .Substitute(s1, Chr(157), Chr(7))
    'remove leading, trailing, multiple spaces (inc. what was 160's)
    s1 = .Trim(s1)
    'remove 0 - 31 (inc. what was 127, 129, 141, 143, 144, and 157)
    SuperClean = .Clean(s1)
    End With
    End Function
    [/vba]

    Paul

  7. #7
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Here is a quick example. You could replace my Trim() with Paul's SuperClean if you need more cleanup.

    Of course JON's method is easy enough. Put that formula in B1 and copy down. Then paste that column to A1. One typically inserts a column to do the scratch work.

    [vba]Sub TrimSpaces()
    Dim cell As Range
    [a1] = "ken "
    [a2] = " ken"
    [a3] = " ken "
    [a4] = "ken"

    For Each cell In Range("A1", Range("A" & Rows.Count).End(xlUp))
    cell.Value = Trim(cell.Value)
    Next cell
    End Sub[/vba]

    Mdmackillop's KB file is corrupted since all KB zip files were corrupted after the forum was restored. Zack is working on a plan to get those entries replaced but it will take some work.

  8. #8

    Thanks

    The Trim Function worked fine

  9. #9
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    hi
    this is how i usually do it:
    select the column,
    then Data->Text to Columns ->Fixed Width ->remove all column breaks
    this will remove all the spaces at the end

    zach

  10. #10

    solved

    thanks for the last post that worked a treat

Posting Permissions

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