I created a dropdown by dragging the combo box onto my sheet from the UserForm toolbar. I assigned some values to it from some cells in the book. Now I want some VBA code to access the selected dropdown item's value in the form of a string.
My dropdown contains only text.
Also how do I find the name of this newly created dropdown (it's nowhere in the properties!)?
Here's how you get the String without needing to know the name:
Lance Roberts was almost there. If you don't know the name of the drop down that calls the sub, use this:
I used this to create a generic sub for a form with many drop downs.
This is a clunky way of doing it but it should work:
There is also a hidden
DropDowns
collection member of theWorksheet
object that you could iterate over. This will find items inserted from theForms
toolbar but won't find items inserted from theControl Toolbox
toolbarNOTES:
DropDown is not a visible class. You just use it and it works.
To find the name of the dropdown CONTROL (not userform) just look at
the name box in the top left corner of your screen just above column A. It says the name of the control when you right click on your control.-
Sheet2 is where the dropdown list is populated. So wherever your list data is.
Hope that helps you all.