excel - VBA - Get Selected value of a Combobox -


I have thousands of cells in the worksheet that are comboboxes, the user will select at random and populate it.

How do I get the selected ComboBox value? Is there a way to speed up a function (ie an event handler) when ComboxBoxes has been selected?

Text after "div class =" itemprop = "text">

If you are working with the data validation list, you can use the Worksheet_Change event . Right click on the sheet with data validation and select View code. Then type:

  range as private sub Worksheet_Change (ByVal Target) MsgBox Target.Value End Sub   

You can work with ActiveX comboboxes To hook up events, this is a bit more complex. First of all, you need to create a custom class module, create a class module named CComboEvent and put this code in it.

  public WithEvents cbx MSForms.ComboBox Private Sub Cbx_Change () MsgBox Cbx.Value End as Sub   

Next, create a class module that CCOOVOVENT says it will hold all our CComboEvent instances and keep them in the scope. Keep this code in CComboEvents.

  private mcolComboEvents personal sub Class_Initialize () sets mcolComboEvents = New Collection End Sub as private sub Class_Terminate () sets mcolComboEvents = Nothing End Sub Public Sub Add (clsComboEvent CComboEvent ) mcolComboEvents.Add clsComboEvent, clsComboEvent.Cbx.Name end Sub   

finally, create a standard module (not a class module). You will need the code by putting all your combobox in the class module. You can put an Auto_Open in the process, so this happens whenever the workbook is opened, but it is up to you.

You will need a public variable to hold an instance of CComboEvents. It must be made public, and in all its children, you need them in the area so that the events can start. In the process, loop through all the combobox, is making a new CComboEvent example for each one, and adding it to CComboEvents.

  public sub addCombox (as public gclsComboEvents CCssEvents) for each Auli Set CComboEvent as OLEObject dim ClsComboEvent as dim OLEO gclsComboEvents = new CComboElents Sheet1. OLEObjects If TypeName (oleo.Object) set = "combo box" in clsComboEvent = new CComboEvent Set clsComboEvent.Cbx = oleo.Object gclsComboEvents.Add clsComboEvent end if Next Ole and all   

Now, whenever a combo box changes, the event will fire and in this example, a message box will appear.

You

P>

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -