How do i get the selected value of the combobox?
i have a combobox which has the values: "Corporate" and "Consumer".
I want to get the value that i selected, not the index, and store in a string.
something like this:
string a = combobox.value;
(a -> Consumer)
thank you
If your ComboBox is embedded in a spreadsheet you can use this:
Dim ws as Worksheet
Dim cboCorpConsumer as ComboBox
Dim a as String
Set ws = Worksheets("YourWorksheetName")
Set cboCorpConsumer = ws.OLEObjects("cboNameFromActiveXProperties").Object
a = cboCorpConsumer.Value
Or in one line:
a = Worksheets("YourWorksheetName").OLEObjects("cboNameFromActiveXProperties").Object.Value
Value
has a capital "V" in VBA, but assuming combobox
is the name of the ComboBox you created on the screen, the code you have will work (except that your assignment statement is wrong; see below). If you don't know what the name of the ComboBox is, it is likely ComboBox1
. To check, look at the Name
property in the VBA properties window.
Try this:
Dim a as String
a = combobox.Value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With