Additem commandButton in listbox

johnster

New Member
Joined
May 31, 2018
Messages
43
Hello,

I have a sheet (sheet1) with products (row B) and one with prices (C).
Next i have a userform (UserForm1) with all the products and a listbox (ListBox1).

When i'm clicking on a commandbutton then i want to see my product and price near each other.

This is my code that i have so far...

Private Sub CommandButton6_Click()
Dim cell As Range
Dim rng As Range
ListBox1.ColumnCount = 2
With ThisWorkbook.Sheets("Sheet1")
Set rng = .Range("B7:C7")
End With
For Each cell In rng.Cells
With Me.ListBox1
.AddItem cell.Value
ListBox1.Column(0, ListBox1.ListCount - 1) = cell.Value
ListBox1.Column(1, ListBox1.ListCount - 1) = cell.Value
End With
Next cell
End Sub

See image for my userform
e6NqHd
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Remove that event code, you don't need it.
 
Upvote 0
Have you added this line to all your commandbuttons?
Code:
Me.TextBox1.Value = CDbl(Me.TextBox1.Value) + .Range("C2").Value
Changing the range to suit.
 
Upvote 0
In that case can you supply a new version of your workbook, as on the last version it worked for me.
 
Upvote 0
Why you are getting that I've no idea. With the file you supplied in post#15 if I click twice on Coca Cola I get 3.2 in the textbox. Have you changed the textbox at all?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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