Hi SG,

This code below should help you. You can run it from the vba ide in the 
attached file.
I'm not as comfortable as Don is with vba objects and methods so maybe 
Don's code is better for this.
I don't run if it takes time for many rows, ask again i like to search on 
the web trick to improve coding syntax.

Hope this answers what you need, 

Pascal Baro

Sub SGTest()

Dim wbIn As Workbook
Dim wsIn As Worksheet
Dim wsInOut As Worksheet
Dim v() As Variant
Dim r As Range
Dim rCol As Integer
Dim i As Long, j As Long
Dim lastr As Long, lastc As Long

Set wbIn = Workbooks("Book1 - Copy.xlsm")
'Set wsInOut = wbIn.Worksheets.Add: wsInOut.Name = "sorted data ok2"
Set wsInOut = wbIn.Worksheets("sorted data")
Set wsIn = wbIn.Worksheets("splitted data")

With Application
    .Calculation = xlCalculationManual
    .DisplayAlerts = False
    .ScreenUpdating = False
End With

lastc = 0
wsIn.Rows(1).Copy wsInOut.Rows(1)
lastr = wsIn.Cells(Rows.Count, 8).End(xlUp).Row

For i = lastr To 2 Step -1

    Set r = wsIn.Range(wsIn.Cells(i, 8), wsIn.Cells(i, 
wsIn.Columns.Count).End(xlToLeft))
    rCol = r.Columns.Count
    
    If rCol > 1 Then
        v = Array(r)
        wsIn.Rows(i + 1 & ":" & i + rCol - 1).Insert
        
        wsIn.Range(wsIn.Cells(i, 1), wsIn.Cells(i, 7)).Copy _
        wsIn.Range(wsIn.Cells(i + 1, 1), wsIn.Cells(i + rCol - 1, 7))
        
        wsIn.Range(wsIn.Cells(i, 8), wsIn.Cells(i + rCol - 1, 8)).Value = _
        Application.WorksheetFunction.Transpose(v)
        
        If rCol > lastc Then lastc = rCol
        
    End If
    
Next i

lastr = wsIn.Cells(Rows.Count, 8).End(xlUp).Row
wsIn.Range(wsIn.Cells(1, 9), wsIn.Cells(lastr, lastc + 9)).ClearContents

With Application
    .Calculation = xlCalculationAutomatic
    .DisplayAlerts = True
    .ScreenUpdating = True
End With

Set r = Nothing
Set wbIn = Nothing
Set wsIn = Nothing
Set wsInOut = Nothing

End Sub

-- 
-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to [email protected]

To unsubscribe, send a blank email to [email protected]


Attachment: Book1 - Copy.xlsm
Description: application/vnd.ms-excel.sheet.macroenabled.12

Reply via email to