+ Reply to Thread
Results 1 to 11 of 11

remove whitespace or tabs

Hybrid View

  1. #1
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    remove whitespace or tabs

    HI ALL.

    I'm looping through an array and trying to remove any leading or ending whitespace but I can't seem to figure out why it's not working as I get extra values which I believe are hidden TABS. Here is my code below to try and clean the array value . What am I doing wrong.


    myArray = Split(TextBox1.Value, Chr(13))
    
    
     For x = LBound(myArray) To UBound(myArray) 'define start and end of array
    
    
               f = myArray(x)
               f = Replace(f, vbLf, "")
               f = Replace(f, " ",
    "")

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: remove whitespace or tabs

    Does this work?
    f= Application.Trim(Application.Clean(f))

  3. #3
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: remove whitespace or tabs

    Just tried and it did not work. AHHHHHHHHH!!

    Tracy

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: remove whitespace or tabs

    How is it not working?

    No change?

    Do you have a line like
    myArray(x)=f
    after the line?

    Otherwise I need to see actual string.

  5. #5
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: remove whitespace or tabs

    this is what I have while looping. it's a mess.


      f = "a" & myArray(x)
              f = Replace(f, vbLf, "")
              f = Replace(f, " ", "")
              f = Trim(f)
              f = Application.Trim(Application.Clean(f))

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: remove whitespace or tabs

    For x = LBound(myArray) To UBound(myArray)
        myArray(x) = Replace(Application.Clean("a" & myArray(x))," ","")
    Next
    Should do.

  7. #7
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: remove whitespace or tabs

    still dont work. What I did was in a text file i simply enter numbers. I would type 22 hit enter then hit tab enter 23 tab tab enter 24. I copied this into my userform and submitted it into an array and get 6 values 3 of them blank because of the tab.


    22

    23


    24

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: remove whitespace or tabs

    Then try
    'Your code
    For x = LBound(myArray) To UBound(myArray)
        myArray(x) = CleanAll("a" & myArray(x))
    Next
    ' Your code
    Add this function somewhere outside above procedure.
    Function CleanAll(ByVal txt As String) As String
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "[\n\t\v\f\s]+"
            CleanAll = .Replace(txt, "")
        End With
    End Function

  9. #9
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: remove whitespace or tabs

    I'll give it a try now and reply back

  10. #10
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: remove whitespace or tabs

    still not working

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: remove whitespace or tabs

    Every suggestion I gave is working here, so no idea why it doesn't work at your side.

+ 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