I have a useform with multicolumn listbox which lists items and its quantity. The intent is to be able to dynamically update the quantity by adding or deducting from a textbox input. Below is my current code roughly to realize this. So far it is not working with invalid qualifier error for selected(i). would appreciate any guidance on this
Private Sub CB_AddOrder_Click()
Dim j, k, qty As Integer
Dim i As Variant
qty = TB_Qty.Value
If qty = 0 Then
Exit Sub
End If
j = LB_Order.ListCount - 1
Debug.Print j
If j < 0 Then
j = 0
End If
'Iterate to check if selected menu already existed in ordered list
For i = 0 To LB_Menu.ListCount - 1
If LB_Menu.Selected(i) = True Then
Debug.Print Selected(i)
For k = 0 To j
If LB_Menu.Selected(i).List(i, 0) = LB_Order.List(k, 0) Then
LB_Order.List(k, 3) = LB_Order.List(k, 3).Value + qty
Exit Sub
End If
Next k
With LB_Order
.ColumnCount = 5
.ColumnWidths = "120;60;60;60;60"
.AddItem
.List(j, 0) = LB_Menu.List(i, 0)
.List(j, 1) = LB_Menu.List(i, 1)
.List(j, 2) = LB_Menu.List(i, 2)
.List(j, 3) = qty
.List(j, 4) = Format(qty * LB_Menu.List(i, 2), "0.00")
End With
End If
Next i
End sub
.List(i, 0)as a qualifier toSelected(i). You'll have to grab the selected index and store the.List(i, 0)in a variable, then use that to compare toLB_Order.List(k, 0)if yourIfstatement.