+ Reply to Thread
Results 1 to 3 of 3

Calling a macro from a ComboBox

Hybrid View

  1. #1
    Registered User
    Join Date
    04-13-2010
    Location
    Australia, Brisbane
    MS-Off Ver
    Excel 2003
    Posts
    5

    Calling a macro from a ComboBox

    I have a combobox (called Combobox 6) which has a Control Source of 'DropBoxLists!Y2'.
    After selecting a choice from the combobox list, I wish to activate a macro called 'ManualClassListSorter'.

    I currently have the following code ...
    Private Sub ComboBox6_Change()
    Call ManualClassListSorter
    End Sub
    Unfortunately, while it is doing the job, the combobox seems to need me to click my choice twice (or more) before it will display my list choice in the combobox window, and it seems to be performing an endless number of activations of the macro, so the program therefore runs extremely slowly and poorly.

    Alternatively, I've tried the following code in an attempt to get the macro to run whenever there is a change in cell Y2 in the sheet 'DropBoxLists', but as the cell is changing dynamically, and not due to a direct key-stroke entry, the code seems to do nothing ...
    Private Sub Worksheet_SelectionChange (ByVal Target As Range)
    If Target.Address = "$Y$2" Then
    ManualClassListSorter
    End If
    End Sub
    Can anyone think of a way to fix my combobox code so the combobox can be used as normal .. ie: just one click needed to make, and display, my choice ?
    Last edited by royUK; 04-14-2010 at 01:31 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Calling a macro from a ComboBox

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Code tags added this time
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Calling a macro from a ComboBox

    You should try using the Change_Event
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$Y$2" Then
            ManualClassListSorter
        End If
    End Sub
    What type of ComboBox are you using? If it's from the Controls TolBox then this shouldwork
    Option Explicit
    
    Private Sub ComboBox1_Change()
     ManualClassListSorter
    End Sub
    Last edited by royUK; 04-14-2010 at 01:37 AM.

+ 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