+ Reply to Thread
Results 1 to 3 of 3

ComboBox selection activate sub

Hybrid View

  1. #1
    Registered User
    Join Date
    05-11-2007
    Location
    Belgium
    Posts
    68

    ComboBox selection activate sub

    Hi,

    When the user makes a choice (selection) in the combobox he should activate a sub depending on his choice. How can I do this ?

      Sheet1.ComboBox1.AddItem "(All)"
      Sheet1.ComboBox1.AddItem "Actual "
      Sheet1.ComboBox1.AddItem "Actual Month"
      Sheet1.ComboBox1.AddItem "Actual Month Country"

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    There is Application.Run -
    Private Sub ComboBox1_Click()
        Select Case ComboBox1.ListIndex
            Case 0
                Application.Run "All"
            Case 1
                Application.Run "Actual"
        End Select
    End Sub
    
    Sub all()
        MsgBox "all running"
    End Sub

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Matrixknow,

    A Control Toolbox ComboBox can have multiple columns. The macro to be run can be inserted in a column next to the item that will be displayed. When a choice is made, the adjacent column's string (the macro name) is pulled and executed.

    Macro to Load ComboBox:
    Change the Items and Macros to what you need.
    Sub LoadComboBox1()
    
      Dim I As Long
      Dim Items
      Dim Macros
      
        Items = Array("Item 1", "Item 2", "Item 3")
        Macros = Array("Macro 1", "Macro2", "Marco 3")
        
        With ActiveSheet.ComboBox1
          .Clear
          For I = 0 To UBound(Items)
            .AddItem Items(I)
            .List(I, 1) = Macros(I)
          Next I
        End With
      
    End Sub
    ComboBox1 Code:
    Private Sub ComboBox1_Click()
    
      With ComboBox1
        Application.Run .List(.ListIndex)
      End With
      
    End Sub
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1