waynerenaud
IS-IT--Management
Hi, I have a multicolumn listbox on userform1 that gets populated from the userform activate event.
The list has 3 columns (Col0,Col1,Col2)ie:
Col0 Col1 Col2
Item Cost Qty
Eggs $1.99
Bacon $4.50
Col2 (Qty) is blank.
If a user selects an item I want to change the entry in Col2 to a 1 for the selected item, (or preferably have a method that defaults to 1, but alows them to put in a greater quantity if required)
I have tried the following code (commented out the line that doesn't work)
Private Sub ListBox1_Change()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
'ListBox1.Column(2, i) = 1 'Doesn't work
ShopValue = ListBox1.Column(1, i)
RunningTotal = RunningTotal + ShopValue
UserForm1.Label1.Caption = "$" & RunningTotal
End If
Next i
End Sub
Is it possible to write an entry to a column of a selected item in a listbox and if so how??. In frustration I also tried the deleteitem and additem method but couldnt figure out how to capture the existing data in col0 & col1 to add col2 data to it. (Also couldn't understand the syntax at all for the additem & deleteitem). Any Help would be greatly appreciated as I have been pulling my hair out for hours & hours. Thanks
The list has 3 columns (Col0,Col1,Col2)ie:
Col0 Col1 Col2
Item Cost Qty
Eggs $1.99
Bacon $4.50
Col2 (Qty) is blank.
If a user selects an item I want to change the entry in Col2 to a 1 for the selected item, (or preferably have a method that defaults to 1, but alows them to put in a greater quantity if required)
I have tried the following code (commented out the line that doesn't work)
Private Sub ListBox1_Change()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
'ListBox1.Column(2, i) = 1 'Doesn't work
ShopValue = ListBox1.Column(1, i)
RunningTotal = RunningTotal + ShopValue
UserForm1.Label1.Caption = "$" & RunningTotal
End If
Next i
End Sub
Is it possible to write an entry to a column of a selected item in a listbox and if so how??. In frustration I also tried the deleteitem and additem method but couldnt figure out how to capture the existing data in col0 & col1 to add col2 data to it. (Also couldn't understand the syntax at all for the additem & deleteitem). Any Help would be greatly appreciated as I have been pulling my hair out for hours & hours. Thanks