+ Reply to Thread
Results 1 to 5 of 5

Thread: Split column and create new row

  1. #1
    Registered User
    Join Date
    01-13-2012
    Location
    Riverside, CA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Split column and create new row

    Hello,

    I have a spreadsheet with multiple columns. Each colunm has a single entrey except for column D (happens to be in the middle). Column D has multiple entries separated by £. I would like to take column D and split it and make a new row that duplicates columns A - C & E - G for each entry in column D. I'm using the following script but it does not copy the info from columns a-c and e-g.

    Sub Splt()
    Dim LR As Long, i As Long
    Dim X As Variant
    Application.ScreenUpdating = False
    LR = Range("A" & Rows.Count).End(xlUp).Row
    Columns("K").Insert
    For i = LR To 1 Step -1
    With Range("E" & i)
    If InStr(.Value, "£") = 0 Then
    .Offset(, -1).Value = .Value
    Else
    X = Split(.Value, "£")
    .Offset(1).Resize(UBound(X)).EntireRow.Insert
    .Offset(, -1).Resize(UBound(X) - LBound(X) + 1).Value = Application.Transpose(X)
    End If
    End With
    Next i
    Columns("E").Delete
    LR = Range("A" & Rows.Count).End(xlUp).Row
    With Range("A1:J" & LR)
    On Error Resume Next
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]J"
    On Error GoTo 0
    .Value = .Value
    End With
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,381

    Re: Split column and create new row

    Why dont you attach your sample spreadsheet?

    Also, as per the forum rules, put your code within code tags. Its easier for others to work with it and you will get a solution faster.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-13-2012
    Location
    Riverside, CA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Split column and create new row

    I will thank you for your reply!

    Cheers!
    Jack

  4. #4
    Registered User
    Join Date
    01-13-2012
    Location
    Riverside, CA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Split column and create new row

    Here's an example of the spreadsheet. Please note that the code attached works to some extent but it does not copy the data in columns a-c and e-i to the necesary columns.
    Attached Files Attached Files

  5. #5
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,381

    Re: Split column and create new row

    Column D in your attachment is blank. Maybe you attached the wrong file.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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.2.0