+ Reply to Thread
Results 1 to 3 of 3

Run different macros based on userform checkbox values

Hybrid View

nymanns Run different macros based on... 11-13-2013, 10:15 AM
stnkynts Re: Run different macros... 11-13-2013, 11:08 AM
nymanns Re: Run different macros... 11-13-2013, 06:26 PM
  1. #1
    Registered User
    Join Date
    03-16-2013
    Location
    DK
    MS-Off Ver
    Excel 2010
    Posts
    16

    Run different macros based on userform checkbox values

    Hi all

    Have been looking around to see if I could find the solution to my problem myself, but I have come up short..

    Basically I am creating a userform containing 6 different checkboxes, 2 optionbuttons & 1 commandbutton.
    I have 12 different macros (2 sets each with 6 macros), which must run depending on the selections made.

    In short:
    Any combo of the 6 checkboxes is possible

    The option button decides whether to run a combo of the 6 macros in set 1 (based on user selection in the 6 checkboxes), or a combo of the 6 macros in set 2 (Still based on the user selection in the 6 checkboxes)

    The command button executes the choices made..

    If for example the user chooses checkbox 2, 4 & 6

    If option button 1 is chosen - Then when U click RUN, macro no# 2, 4 & 6 must be run/called..
    If option button 2 is chosen - Then when U click RUN, macro no# 8, 10 & 12 must be run/called..

    Example picture of userform attached..

    If anyone has a solution to the above please let me know.

    Regards
    Henrik
    Attached Images Attached Images

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Run different macros based on userform checkbox values

    The direct answer is to set up a bunch of If Statements. Something like this:

    Private Sub CommandButton1_Click()
    
    If OptionButton1.Value = True Then
        If ComboBox1.Value = True Then Call Macro1
        If ComboBox2.Value = True Then Call Macro2
        'etc
        'etc
    Else
        If ComboBox1.Value = True Then Call Macro8
        'etc
        'etc
    End If
    
    End Sub
    This is by no means the best way, but given the limited information, it is a solution.

  3. #3
    Registered User
    Join Date
    03-16-2013
    Location
    DK
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Run different macros based on userform checkbox values

    Hi again

    Solved the issue I had..
    The problem was quite small but yet for me very easy to miss..
    I use an english version of Excel at work, and a danish version at home..

    In english it's spelled "MACRO" but in danish it's spelled "MAKRO"

    So with minor adjustments, using checkboxes and not comboboxes, below code works perfect for me..

    Sub OnExecute()
    
    If UserForm1.OptionButton1.Value = True Then
        
        If UserForm1.CheckBox1.Value = True Then
            Call Makro1
        End If
        If UserForm1.CheckBox2.Value = True Then
            Call Makro2
        End If
        If UserForm1.CheckBox3.Value = True Then
            Call Makro3
        End If
        If UserForm1.CheckBox4.Value = True Then
            Call Makro4
        End If
        If UserForm1.CheckBox5.Value = True Then
            Call Makro5
        End If
        If UserForm1.CheckBox6.Value = True Then
            Call Makro6
        End If
        'etc
        'etc
    Else
        
        If UserForm1.CheckBox1.Value = True Then
            Call Makro7
        End If
        If UserForm1.CheckBox2.Value = True Then
            Call Makro8
        End If
        If UserForm1.CheckBox3.Value = True Then
            Call Makro9
        End If
        If UserForm1.CheckBox4.Value = True Then
            Call Makro10
        End If
        If UserForm1.CheckBox5.Value = True Then
            Call Makro11
        End If
        If UserForm1.CheckBox6.Value = True Then
            Call Makro12
        End If
        'etc
        'etc
    End If
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Hide rows based on userform checkbox
    By rodrignj in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-21-2015, 05:38 AM
  2. Saving and changing values based on a checkbox
    By kaligad in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-19-2012, 08:04 AM
  3. Replies: 4
    Last Post: 11-28-2012, 06:09 PM
  4. Run different Macros based on what selections have been made in checkbox
    By vetteengr in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-13-2012, 01:13 PM
  5. Dynamic Userform (resizing based on checkbox selection)
    By gazza365 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2011, 04:50 PM

Tags for this Thread

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