+ Reply to Thread
Results 1 to 15 of 15

splitting text into rows.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-18-2013
    Location
    NY, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    splitting text into rows.

    Hi all,

    I'm new to VBA and I'm looking for a macro which would do the following:

    I have this:
    555545, 4555
    42225, 44
    4444, 5, 4445, 88, 986

    and I want this:

    555545
    4555
    42225
    44
    4444
    5
    4445
    88
    986


    Many thanks in advance!

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: splitting text into rows.

    Assuming your list starts in A1:

    Sub rose9812in()
    Application.ScreenUpdating = False
    i = Cells(Rows.Count, "A").End(xlUp).Row
    Do While i > 0
        temp = Split(Cells(i, 1).Value, ",")
        For j = UBound(temp) To 0 Step -1
            Rows(i).Insert
            Cells(i, 1).Value = temp(j)
        Next
        Rows(i + UBound(temp) + 1).EntireRow.Delete
    i = i - 1
    Loop
    Application.ScreenUpdating = True
    End Sub
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Registered User
    Join Date
    07-18-2013
    Location
    NY, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: splitting text into rows.

    This worked perfectly! Thank you very much. What if the list doesn't start from A1 and starts from A5?

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: splitting text into rows.

    Do While i > 4

  5. #5
    Registered User
    Join Date
    07-18-2013
    Location
    NY, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: splitting text into rows.

    Thanks again for your prompt response. Another question related to this topic. What if I would like to do this for multiple columns, A, B & C all at once?

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: splitting text into rows.

    Can you post a before and after of the start and end results you want like you did in your first post?

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: splitting text into rows.

    FWIW:
    Sub rose9812in()
    Dim i As Long, x As Long
    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
        .Calculation = xlManual
    End With
    Range("A2:A" & Range("A" & Rows.Count).End(3).row).TextToColumns Range("A2"), xlDelimited, xlDoubleQuote, False, True, False, True, False, True
    For i = Range("A" & Rows.Count).End(3).row To 2 Step -1
    x = Cells(i, "A").End(xlToRight).Column
    Cells(i + 1, "A").Resize(x).Insert xlDown
    Range(Cells(i, "B"), Cells(i, x)).Copy
    Cells(i + 1, "A").PasteSpecial Transpose:=True
    Range(Cells(i, "B"), Cells(i, x)).Clear
    Next i
    Range("A2:A" & Range("A" & Rows.Count).End(3).row).SpecialCells(4).Delete
    With Application
        .DisplayAlerts = True
        .Calculation = xlAutomatic
        .ScreenUpdating = True
    End With
    End Sub

  8. #8
    Registered User
    Join Date
    07-18-2013
    Location
    NY, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: splitting text into rows.

    Thanks but this is not what I was looking for. The Macro provided by John H. Davis moved all the values to Column A.

    This is what I have:

    115, 54 454, 245, 5454 545
    45, 548, 855 45 10, 11
    45, 5 2 3, 4

    And this is what I want:

    115 454 545
    54 245 10
    45 5454 11
    548 45 3
    855 2 4
    45
    5

  9. #9
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: splitting text into rows.

    Try this:

    Sub rose()
    Dim rng As Variant, vSplit As Variant
    Dim i As Integer
    
    For i = 1 To 3 'column A,B,C
        rng = Join(Application.Transpose(Range(Cells(5, i), Cells(Cells(Rows.Count, i).End(xlUp).Row, i))), ",")
        vSplit = Split(rng, ",")
        Cells(5, i).Resize(UBound(vSplit) + 1).Value = Application.Transpose(vSplit)
    Next i
    
    End Sub
    If you are happy with my response please click the * in the lower left of my post.

  10. #10
    Registered User
    Join Date
    07-18-2013
    Location
    NY, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: splitting text into rows.

    This is not working for me . I might have to edit it based on the way my data is set up. Could you explain what Cells(5,i) is referring to?

    Thanks!

  11. #11
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: splitting text into rows.

    @stnkynts: Beautiful approach, put me to shame this time. Nice job.

  12. #12
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: splitting text into rows.

    @walrus. Thank you kindly

    @rose. In general terms Cell(5, i) is a range which is further defined by the integer i, which based upon the loop is either 1, 2, or 3. When i is 1 the range will be Cells(5, 1) otherwise known as A5.

  13. #13
    Registered User
    Join Date
    07-18-2013
    Location
    NY, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: splitting text into rows.

    @stnkynts - Thanks for your explanation. But unfortunately, the code is not working for me. It is only inputting one value for cell A5; and all other cells (A1:C3) remains the same.

    @stnkynts and/or @walruseggman - Can you write similar to what @walruseggman had provided earlier?

    Thanks!

  14. #14
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: splitting text into rows.

    It is only inputting one value for cell A5; and all other cells (A1:C3) remains the same.
    You previously indicated you wanted it to start at row 5 and so I coded it to start at row 5. If you want it to start at row 1 you would need to change the code to reflect this:

    Sub rose()
    Dim rng As Variant, vSplit As Variant
    Dim i As Integer
    
    For i = 1 To 3 'column A,B,C
        rng = Join(Application.Transpose(Range(Cells(1, i), Cells(Cells(Rows.Count, i).End(xlUp).Row, i))), ",")
        vSplit = Split(rng, ",")
        Cells(1, i).Resize(UBound(vSplit) + 1).Value = Application.Transpose(vSplit)
    Next i
    
    End Sub

  15. #15
    Registered User
    Join Date
    07-18-2013
    Location
    NY, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: splitting text into rows.

    @stnkynts - This worked perfectly! Thank you!

+ 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. Splitting an 8 sheet WB with 46,000 rows into smaller WB with 1000 rows?
    By Konakick in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-16-2015, 08:11 PM
  2. Splitting rows with multiple columns into seperate rows for time points.
    By mbracha in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-16-2013, 10:06 AM
  3. Macro splitting comma delimated cell text into rows with other row data copied...
    By geoffffffff in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2013, 11:07 AM
  4. [SOLVED] Splitting text from one cell into separate text fragments, Located in adjacent cells
    By onsid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2013, 08:32 PM
  5. Splitting one row into two rows
    By Adrow1x in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-21-2012, 04:48 PM
  6. Splitting a row into 2 rows
    By dilly.sg in forum Excel General
    Replies: 1
    Last Post: 05-29-2012, 12:26 AM
  7. Replies: 3
    Last Post: 11-13-2009, 12:05 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