Hello all! I appreciate any time and help anyone can give me. I am trying to figure out how to extract data selected on a multi-column list box and a textbox from a user form into the next available rows of a sheet, this is for entering takeout orders on a sort of log. As you can see the list box is populated from Sheet1, Ctrl+y opens up my user form, in there I have a multi-column list box with the items (column 1) and price for each (column 2), as well as a text box in which you type in the address for where those items must be sent out to.
So far, I am able to select multiple items from the list and copy them along with the text box value next to them onto Sheet2 (address in column a and items in column b), but i can't seem to find a way of copying the price for each item onto column c.
Hope I am clear enough with regards to my issue!
Best regards,
Nick S
Private Sub CommandButton1_Click()
Dim NextBlankRow As Long
Dim TargetRange As Range
Dim ListBoxItem As Long
Dim SelectedItemsArray As Variant
Dim ArrayElementCounter As Long
ArrayElementCounter = 0
With Me.ListBox1
ReDim SelectedItemsArray(0 To .ListCount - 1)
For ListBoxItem = 0 To .ListCount - 1
If .Selected(ListBoxItem) Then
SelectedItemsArray(ArrayElementCounter) = .List(ListBoxItem)
ArrayElementCounter = ArrayElementCounter + 1
End If
Next ListBoxItem
End With
ReDim Preserve SelectedItemsArray(0 To ArrayElementCounter - 1)
With ThisWorkbook.Sheets("Sheet2")
NextBlankRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
Set TargetRange = .Range("A" & NextBlankRow & ":A" & NextBlankRow + UBound(SelectedItemsArray))
End With
Dim TargetCell As Range
ArrayElementCounter = 0
For Each TargetCell In TargetRange
TargetCell.Value = Me.TextBox1.Value
TargetCell.Offset(0, 1).Value = SelectedItemsArray(ArrayElementCounter)
TargetCell.Offset(0, 2).Value = UserForm1.ListBox1.List(ListBox1.ListIndex, 2) 'HERE IS WHERE I CRASH AND BURN
ArrayElementCounter = ArrayElementCounter + 1
Next TargetCell
End Sub
So far, I am able to select multiple items from the list and copy them along with the text box value next to them onto Sheet2 (address in column a and items in column b), but i can't seem to find a way of copying the price for each item onto column c.
Hope I am clear enough with regards to my issue!
Best regards,
Nick S
Private Sub CommandButton1_Click()
Dim NextBlankRow As Long
Dim TargetRange As Range
Dim ListBoxItem As Long
Dim SelectedItemsArray As Variant
Dim ArrayElementCounter As Long
ArrayElementCounter = 0
With Me.ListBox1
ReDim SelectedItemsArray(0 To .ListCount - 1)
For ListBoxItem = 0 To .ListCount - 1
If .Selected(ListBoxItem) Then
SelectedItemsArray(ArrayElementCounter) = .List(ListBoxItem)
ArrayElementCounter = ArrayElementCounter + 1
End If
Next ListBoxItem
End With
ReDim Preserve SelectedItemsArray(0 To ArrayElementCounter - 1)
With ThisWorkbook.Sheets("Sheet2")
NextBlankRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
Set TargetRange = .Range("A" & NextBlankRow & ":A" & NextBlankRow + UBound(SelectedItemsArray))
End With
Dim TargetCell As Range
ArrayElementCounter = 0
For Each TargetCell In TargetRange
TargetCell.Value = Me.TextBox1.Value
TargetCell.Offset(0, 1).Value = SelectedItemsArray(ArrayElementCounter)
TargetCell.Offset(0, 2).Value = UserForm1.ListBox1.List(ListBox1.ListIndex, 2) 'HERE IS WHERE I CRASH AND BURN
ArrayElementCounter = ArrayElementCounter + 1
Next TargetCell
End Sub