+ Reply to Thread
Results 1 to 2 of 2

Splting a long string, at the spaces, with a max length of 24

Hybrid View

  1. #1
    Registered User
    Join Date
    08-10-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    12

    Splting a long string, at the spaces, with a max length of 24

    Hi team,

    How do you spilt a long string e.g.:

    Some cities, like New York, Las Vegas, and Paris have well-deserved reputations

    To read:

    Some cities, like New
    York, Las Vegas, and
    Paris have well-deserved
    reputations

    so the Max length of each new string is 24.
    Last edited by bassima; 12-15-2011 at 02:27 AM.

  2. #2
    Registered User
    Join Date
    08-10-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Splting a long string, at the spaces, with a max length of 24

    Ok found the answer myselft:

    Sub SpliteAtSpace()
    
    Dim sLong As String
    Dim aSplit 
    Dim iCounter As Variant
    Dim sLine1 As String
    Dim sLine2 As String
    Dim bLine2 As Boolean
    
        bLine2 = False
        sLong = "Some cities, like New York, Las Vegas, and"
        
        aSplit = Split(sLong, " ")
        
        For Each iCounter In aSplit
        
        If Len(sLine1 & " " & iCounter) < 24 And Not bLine2 Then
        
            sLine1 = sLine1 & " " & iCounter
    
        Else
                
            bLine2 = True
            sLine2 = sLine2 & " " & iCounter
    
        End If
        
        Next iCounter    
        MsgBox (sLine1)
        MsgBox (sLine2)
        
    End Sub
    Last edited by bassima; 12-15-2011 at 07:33 PM.

+ 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