Splitting Data And copying Part 2 (Solved)

Samnuni

Board Regular
Joined
Sep 27, 2005
Messages
206
Previous post: http://www.mrexcel.com/board2/viewtopic.php?t=178752

Hi again, that code worked wonderous, but now I need it to work for more than one input. This is one of the examples of what my sheet looks like with more than 1000 entries:
ZSDE Splitted.xls
ABCDEFG
1CustomerName1MaterialBilling DateQuantityOrder ReasonSerial Numbers
29145CARRAWAY METHODIST MED CTREC-3430L10/27/20052S26( E110879, E110880 )
39145CARRAWAY METHODIST MED CTREC-3831L4/3/20051S26( E01152, E110435, E110444, E11415 )
49145CARRAWAY METHODIST MED CTREC-3832L10/27/20059S26( E110090, E110091, E110092, E110093, E110094, E110095, E110096, E110097, E110098 )
59145CARRAWAY METHODIST MED CTRED-3430T10/27/20052S26( A110647, A110648 )
69145CARRAWAY METHODIST MED CTREG-27314/3/20051S26( A11565, A11759, E111931, E11951, E11966 )
79145CARRAWAY METHODIST MED CTREG-273110/27/20054S26( E131546, E131547, E131548, E131549 )
89145CARRAWAY METHODIST MED CTREG-29314/3/20051S26( E01261, E110433, E110442, E110451, E11338, E11363 )
99145CARRAWAY METHODIST MED CTREG-293110/27/20056S26( E131470, E131472, E131473, E131474, E131475, E131477 )
109145CARRAWAY METHODIST MED CTRFC-38LV10/27/20051S26( A110686 )
119145CARRAWAY METHODIST MED CTRFG-29V10/27/20051S26( A114597 )
9145


The basic code to split the cells and insert into a new row was given from the post I made on top, but for the life of me I can't insert a for loop to make it do all the entries. And seeing that it just replaces the row that it splits, if it can be copy onto a new worksheet, it'll be wonderful. Thank you in advance.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Ok, I figured out how to replace the rows and have the info that I wanted to be filled in. However, I don't know how I can fit a loop in there that will check each row from the raw data...

The code I got for inserting rows and filling it with data:
Code:
Sub test()
Dim x, i As Long
Dim j, k As Integer

With Range("g2")
    txt = .Value
    x = Split(Replace(Replace(Replace(txt, "(", ""), ")", ""), Chr(32), ""), ",")
    For j = 1 To UBound(x)
    ActiveCell.EntireRow.Insert
    Next j
    .Offset(-UBound(x), -6).Resize(UBound(x) + 1, 6) = .Offset(, -6).Resize(, 6).Value
    .Offset(-UBound(x)).Resize(UBound(x) + 1) = Application.Transpose(x)
End With
End Sub

I know I declared k in there and never used it, I was trying to make a Do Until loop to check the last row so it'll stop when it's empty, but the reference cell g2 never changes and I think that's the problem.
 
Upvote 0
Ok, the code works only if I modify it and not run this straight up. The mod was made from a piece of code that I was given on here where instead of using "-Ubound(x)" it was 2. Anyone has any idea why it's like that?

Code:
Sub test()
Dim x, i As Long
Dim j, k As Integer

    Cells.Replace What:="( ", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows
    Cells.Replace What:=" )", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows

For k = 2 To 2000
Cells(k, 7).Select
With ActiveCell
    txt = .Value
    x = Split(txt, ",")
    For j = 0 To UBound(x) - 1
    Cells(k + j, 7).EntireRow.Insert
    Next j
    .Offset(-UBound(x), -6).Resize(UBound(x) + 1, 6) = .Offset(, -6).Resize(, 6).Value
    .Offset(-UBound(x)).Resize(UBound(x) + 1) = Application.Transpose(x)
End With
Next k
End Sub
 
Upvote 0
Code:
Sub test()
Dim x, i As Long
Application.ScreenUpdating = False
With Sheets("9145")
    With .Columns("g")
        .Replace "(", ""
        .Replace ")", ""
    End With
    i = 2
    Do While Not IsEmpty(.Cells(i, "g"))
        If InStr(.Cells(i, "g"), ",") > 0 Then
            x = Split(.Cells(i, "g"), ",")
            .Rows(i + 1 & ":" & i + UBound(x)).Insert
            .Cells(i, "a").Resize(UBound(x) + 1, 6).Value _
                = .Cells(i, "a").Resize(, 6).Value
            .Cells(i, "g").Resize(UBound(x) + 1).Value _
                = Application.Transpose(x)
            i = i + UBound(x)
            Erase x
        End If
        i = i + 1
    Loop
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,207,392
Messages
6,078,221
Members
446,323
Latest member
fishezuk

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top