Question : Excel/csv, move rows to another sheet based on changing value in column

Hi i need some help with moving columns in Excel.
I am not an VBA/Macro expert alhough when i read the code, and chase errors, i understand what is happening.

Our goal is to translate information from the attached CSV file and put the values we need into an XML file.

One of the problems we run into is that the CSV file contains multiple ordernumbers in one file. We would prefer to have an Excel or sheet per ordernumber.

Column C shows `inkooporder` you can see that the values in this column changes. i would like a piece of code that copies the rows where the `inkooporder┬┤ is equal, and pasts it to a new sheet where the sheetname is the ┬┤inkooporder┬┤.
So in the attached example  it show 10 different inkoopordernumbers so this would lead to 10 different sheets.

in the end i would like to copy in new rows from a new CSV, run the macro and it processes again the new information.

hopefully a VBA/expert can help me to build some code.

much appreciated
Attachments:
 
 

Answer : Excel/csv, move rows to another sheet based on changing value in column

Hi,
I have fixed the problems you found.  The following code should now work much better for you:
Sub splitVersion2()

Dim lastOrder, inkooporder As String
Dim rowCount As Integer

lastrow = [b65536].End(xlUp).Row
rowCount = 2
Columns("A:S").Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C2:C34") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A1:S34")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
        ActiveSheet.Cells(1, 1).Select
    End With
lastOrder = 0
For i = 2 To lastrow
    inkooporder = Sheets("Sheet1").Cells(i, 3)
    If Not inkooporder = lastOrder Then
        Worksheets.Add(After:=Worksheets(1)).Name = inkooporder
        Sheets("Sheet1").Select
        Cells.Select
        Selection.Copy
        Sheets(inkooporder).Select
        Cells.Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Range("A1").Select
        For x = 1 To 19
            Sheets(inkooporder).Cells(1, x) = Sheets("Sheet1").Cells(1, x)
        Next x
        rowCount = 2
    End If
    For x = 1 To 19
        Sheets(inkooporder).Cells(rowCount, x) = Sheets("Sheet1").Cells(i, x)
    Next x
    rowCount = rowCount + 1
    lastOrder = inkooporder
Next i
Sheets("Sheet1").Select
Range("A1").Select
End Sub
Random Solutions  
 
programming4us programming4us