VBA code For Combobox (ActiveX) In Sheet

glerwell

Well-known Member
Joined
Jun 25, 2006
Messages
1,082
Hi

I have a ActiveX combobox in my sheet (combobox1). Instead of using the linked cell property can I use a VBA code to display a number instead of the actual value in the combobox.

The combobox consists of 3 options: "OVERALL","PLACED" and "BANK BARRIER". This is populated via a named range which is set in the properties.

So when:

"OVERALL" is selected then 1 is returned in AN24

"PLACED" is selected then 2 is returned in AN24

"BANK BARRIER" is selected then 3 is returned in AN24

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Sure, on the sheet holding the combobox, put

Private Sub ComboBox1_Change()
Range("AN24").Value = ComboBox1.Value
End Sub

Change both instances of ComboBox1 to the actual name of the combobox
 
Upvote 0
In your combobox change event
Code:
If combobox.Value = "OVERALL" Then
    Range("AN24").Value = 1
ElseIf combobox.Value = "PLACED" Then
    Range("AN24").Value = 2
ElseIf combobox.Value = "BANK BARRIER"  Then
    Range("AN24").Value = 3
Else
    Range("AN24").Value = "kpark :)"
End If
 
Upvote 0
Wait, that puts the combobox value in the cell..

You wanted the number...

That would be

Private Sub ComboBox1_Change()
Range("AN24").Value = ComboBox1.ListIndex + 1
End Sub
 
Upvote 0
kpark got your working, I has to add 1 to combobox in the code.

jonmo I'm having a syntax error with yours?
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

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