+ Reply to Thread
Results 1 to 10 of 10

Split text in two columns

  1. #1
    Registered User
    Join Date
    12-20-2015
    Location
    Ekeren
    MS-Off Ver
    Office 2010
    Posts
    17

    Split text in two columns

    Hi everyone,

    In the example I have in column A cells with text, which should be printed on a label. The label has a maximum of 40 characters for each line.
    So if the total characters of this cell is more than 40, it should be split in 2 columns.

    I've managed to split the text, but as you'll see in this example the split is mostly in the middle of a word.
    This in not very readable if it is printed on a label.

    Can anyone help me to find out how the split will be at the maximum of 40 char. and at the end of a word?

    Many thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    According to your attachment a VBA beginner starter :

    PHP Code: 
    Sub Demo1()
          Const 
    40
            Dim V
    S$(), R&, C%
        
    With Blad1.Range("A2:A" Blad1.UsedRange.Rows.Count)
                
    = .Value2
                ReDim S
    (1 To UBound(V), 1)
            For 
    1 To UBound(V)
                If 
    Len(V(R1)) > M Then
                    C 
    InStrRev(V(R1), " "1)
                    
    S(R0) = Left(V(R1), 1)
                    
    S(R1) = Mid(V(R1), 1)
                Else
                    
    S(R0) = V(R1)
                
    End If
            
    Next
               
    .Offset(, 2).Resize(, 2).Value2 S
        End With
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Split text in two columns

    Function:
    Please Login or Register  to view this content.
    Where:
    txt - text to split
    dvdevr - text length (for the first part of the text)
    prt - first or second part of 'txt' text

    For example:
    In 'C2' => =dvdwrds($A2; 40; 1)
    In 'D2' => =dvdwrds($A2; 40; 2)
    and copy down

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Split text in two columns


    Hi porucha !

    Try a little experiment : in cell A3 add a space between the dot and "B"
    Then compare your result in cell C3 with mine
    so you must see your pSpc allocation just needs InstrRev like I used in my demonstration for the variable C …

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Split text in two columns

    And what if the string is > 80 characters?

  6. #6
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Split text in two columns

    use this universal formula start at C2

    =MID(REPT("x",40)&$A2,COLUMNS($A:A)*40+1,40)

    copy cross and down

  7. #7
    Registered User
    Join Date
    12-20-2015
    Location
    Ekeren
    MS-Off Ver
    Office 2010
    Posts
    17

    Re: Hi ! Try this !

    Thanks Marc,
    this works great for me.

    As you already have noticed, I am a beginner I am Always surprised how the experts in this forum solve an issue in a few minutes, while I have spent hours on "google search" and still can't figure it out.

    Can you explain me the "Dim line" please? I recognize dat S$() declares an array, but where stands & and % for?

  8. #8
    Registered User
    Join Date
    12-20-2015
    Location
    Ekeren
    MS-Off Ver
    Office 2010
    Posts
    17

    Re: Hi ! Try this !

    Hey Everybody,

    Many thanks for all your replies. I'm going for the solution of Marc L.

    Keep up the good work!

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Hi ! Try this !

    Quote Originally Posted by starchaser_one View Post
    Can you explain me the "Dim line" please? I recognize dat S$() declares an array, but where stands & and % for?
    First thanks for the rep' !

    Those characters are declaring the variables types as you can see during the execution in the VBE Locals window or
    just in the VBA help for String for example. Without any character the variable is Variant but not for a constant
    as VBA choose a default type according to the constant value …
    It's just a legacy from the VBA grand father : the BASIC !

  10. #10
    Registered User
    Join Date
    12-20-2015
    Location
    Ekeren
    MS-Off Ver
    Office 2010
    Posts
    17

    Re: Split text in two columns

    Thanks for the info
    I will close this post now

    Have a nice day to everyone and keep it safe!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Split text into columns
    By EHH in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-17-2019, 09:27 AM
  2. [SOLVED] Split Text Across Multiple Columns and Add Additional Text
    By Jim Clayton in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 08-20-2018, 09:46 AM
  3. Formula(s) to Split Text String Across Columns Using Columns as Seperator
    By WaylettChris in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-24-2016, 01:13 PM
  4. Replies: 2
    Last Post: 04-09-2014, 11:48 AM
  5. [SOLVED] Split text into columns help
    By darxide23 in forum Excel General
    Replies: 11
    Last Post: 09-28-2013, 06:41 PM
  6. Replies: 4
    Last Post: 07-25-2013, 05:28 AM
  7. Split text into three columns
    By Beginner-in-VBA in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2013, 03:02 PM

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