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
 
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?

Fluff. Will you send me the workbook that’s worked by you? Thx
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
It's the one you supplied in post#15
All I did was remove this
Code:
Private Sub TextBox1_Change()
Me.TextBox1.Value = CDbl(Me.TextBox1.Value) + .Range("C2").Value
Me.TextBox1.Value = CDbl(Me.TextBox1.Value) + .Range("C3").Value
End Sub
Put a value of 0 in the textbox property & added this to one of the buttons
Code:
Me.TextBox1.Value = CDbl(Me.TextBox1.Value) + .Range("C2").Value
 
Upvote 0
I've tested on de pc at work en over there it's working perfect. So i don't understand what's the issue...

Pc at work: Office 2016
Pc at home: Office 2016

Probably is that the issue??
 
Last edited:
Upvote 0
If your using Office 2016 on both PCs, then it should not be a problem.
I'm running it on 2013 & it's fine, so cannot think why it would work on one, but not the other.
 
Upvote 0
I wouldn't have thought that that would be a problem, as I've tested it in 2003 & that works happily.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,628
Members
449,241
Latest member
NoniJ

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