Check value selected in a ComboBox

antares63

New Member
Joined
Jan 24, 2005
Messages
14
Hi,
I have the necessity to include in a only one macro this code

'INITIALIZE text of ComboBox
ThisWorkbook.Sheets(1).ComboBox1.Text = "Select a value"

'ADD 2 values in a conbobox
item = 1
ThisWorkbook.Sheets(1).ComboBox1.AddItem item
item = 2
ThisWorkbook.Sheets(1).ComboBox1.AddItem item

< now I need to select a value in my Sheet1 >

'TEST the value selected
If ThisWorkbook.Sheets(1).ComboBox1.Value = 2 Then
MsgBox "OK!!"
Else
MsgBox "NOT OK!!"
End If

But I receive always the "NOT OK!!" message.

Any Idea?

Thanks in advance.

Giovanni
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
are you sure you are getting two value's? You are showing this

item = 1
combobox.additem item
item = 2
combobox.additem item

looking at that it looks to me as though either you are only getting one choice or the same choice.

I ran your code and it worked fine. But instead of adding the items I made a list: in cell b2 I put Select a value, b3 I put 1 and b4 I put 2.

I right clicked on the combobox chose properties and in the ListFillRange I put B2:B4.

Got both messages.
 
Upvote 0

Forum statistics

Threads
1,203,515
Messages
6,055,854
Members
444,828
Latest member
StaffordStag

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