Another set of eyes needed

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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
In the output section of your code you are using lb1Index instead of i. I haven't looked at this in detail but I'm guessing that is what you need to change....?
Andrew
 
Upvote 0

Forum statistics

Threads
1,214,578
Messages
6,120,361
Members
448,956
Latest member
Adamsxl

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