I have a table with multi columns.
I use a code to transfer all the data from a listbox to an Excel sheet.
The listbox contains an order from 1 client at the time, with different articles the client ordered.
Everything is wroking fine except for the order number. If someone orders 4 articles, the code transfers the 4 lines perfectly but puts the order number in the last row and leaves the cells above blank. I would like that the code puts the order number in the first row of the order an leaves the cells below blank.
This is the code I'm using:
Private Sub cmdBestellen_Click()
Dim r As Long
For r = 1 To Me.lstboxBesteldeArt.ListCount - 1
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = Me.lstboxBesteldeArt.List(r, 0)
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 1) = Me.lstboxBesteldeArt.List(r, 1)
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 2) = Me.lstboxBesteldeArt.List(r, 2)
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 3) = Me.lstboxBesteldeArt.List(r, 3)
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 4) = Me.lstboxBesteldeArt.List(r, 4)
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 5) = Me.lstboxBesteldeArt.List(r, 5)
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 6) = Me.lstboxBesteldeArt.List(r, 6)
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 7) = Me.lstboxBesteldeArt.List(r, 7)
Next r
ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(0, 8) = Sheets("Bestelde Artikelen").Range("M2").Value + 1
Call M_ClearAll2.ClearAll2
Unload Me
End Sub
Display More
When I put the code line (with Range (M2) before "Next r", the code puts the order umber behind every line of the order, that is not what I want. The order should only get one order number.
It doesn't matter where I put the line for the order number, it is always wrong. Could somebody help me please?
Thanks in advance.