BrianExcel
Well-known Member
- Joined
- Apr 21, 2010
- Messages
- 975
I have a listbox populated with records. When I highlight a record and press a button next to it, it runs the following code which removes the selected record:
The problem is, if the user selects a record other than the last one in the list, they (I) get the error: "Could not get the Selected Property. Invalid Argument."
Can anyone suggest any code modifications that will allow the user to remove whichever record they select, regardless of order?
Thanks.
Code:
Dim x As Integer
For x = 0 To UserForm1.lbxStock2.ListCount - 1
If UserForm1.lbxStock2.Selected(x) Then
UserForm1.lbxStock2.RemoveItem (x)
End If
Next x
If UserForm1.lbxStock2.ListCount = 0 Then
UserForm1.lbxStock2.BackColor = vbWindowBackground
End If
The problem is, if the user selects a record other than the last one in the list, they (I) get the error: "Could not get the Selected Property. Invalid Argument."
Can anyone suggest any code modifications that will allow the user to remove whichever record they select, regardless of order?
Thanks.