TonySondergeld
New Member
- Joined
- Jul 11, 2009
- Messages
- 31
I have this code that is to place selections out of a multi-select list box and place them into a worksheet "Production". So what the code is currently doing is, if you select 3 Row in the list box it will place 3 Entry into the worksheet but they are all the same entry date from the last selection in the list box Can't work out or not seeing why. If someone can see why, please let me know. Thanks in advance
the Code I try to use:........
Private Sub CMB_Enter_Click()
Dim ws As Worksheet
Dim i As Long, lb1Index As Long, NextRow As Long
Set ws = Sheets("Production")
NextRow = ws.Range("D" & Rows.Count).End(xlUp).Row + 1
'Check if a selection has been made if not close the userform
If Me.LBX_AddedStock.ListIndex < 0 Then
MsgBox "Missing selection in LBX_Orders", vbExclamation, "Invalid Selection"
Exit Sub
Else
lb1Index = Me.LBX_AddedStock.ListIndex
End If
'Add listbox selection to the worksheet
For i = 0 To Me.LBX_AddedStock.ListCount - 1
If Me.LBX_AddedStock.Selected(i) Then
ws.Range("D" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 0) ' Date
ws.Range("E" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 1) ' Product
ws.Range("F" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 2) ' Pallet Type
ws.Range("G" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 3) ' Batch No.
ws.Range("H" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 4) ' Pallet No.
ws.Range("I" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 5) ' Bags
ws.Range("J" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 6) ' Location of pallet
ws.Range("K" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 7) ' Best Before
'Me.LBX_AddedStock.RemoveItem Me.LBX_AddedStock.ListIndex
NextRow = NextRow + 1
End If
Next i
MsgBox "Order Finished", vbExclamation, "Completed"
Unload Me
End Sub
the Code I try to use:........
Private Sub CMB_Enter_Click()
Dim ws As Worksheet
Dim i As Long, lb1Index As Long, NextRow As Long
Set ws = Sheets("Production")
NextRow = ws.Range("D" & Rows.Count).End(xlUp).Row + 1
'Check if a selection has been made if not close the userform
If Me.LBX_AddedStock.ListIndex < 0 Then
MsgBox "Missing selection in LBX_Orders", vbExclamation, "Invalid Selection"
Exit Sub
Else
lb1Index = Me.LBX_AddedStock.ListIndex
End If
'Add listbox selection to the worksheet
For i = 0 To Me.LBX_AddedStock.ListCount - 1
If Me.LBX_AddedStock.Selected(i) Then
ws.Range("D" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 0) ' Date
ws.Range("E" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 1) ' Product
ws.Range("F" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 2) ' Pallet Type
ws.Range("G" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 3) ' Batch No.
ws.Range("H" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 4) ' Pallet No.
ws.Range("I" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 5) ' Bags
ws.Range("J" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 6) ' Location of pallet
ws.Range("K" & NextRow).Value = Me.LBX_AddedStock.List(lb1Index, 7) ' Best Before
'Me.LBX_AddedStock.RemoveItem Me.LBX_AddedStock.ListIndex
NextRow = NextRow + 1
End If
Next i
MsgBox "Order Finished", vbExclamation, "Completed"
Unload Me
End Sub