+ Reply to Thread
Results 1 to 6 of 6

Assign macro to user form checkbox without running it

Hybrid View

  1. #1
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Assign macro to user form checkbox without running it

    I've created a userform containing multiple checkboxes and I want to assign a macro to each checkbox without running the macro when the checkbox is checked. Ideally, each macro is assigned, you select all the checkboxes planned to run, and afterwards you run all the macros, based on a userform button. Currently it looks like bellow.
    Anyone may have some hints on how to make this possible?
    Attached Images Attached Images
    Click the * to say thanks.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Assign macro to user form checkbox without running it

    That doesn't really make any sense to me. It sounds like what you want is one piece of code that does various things based on what checkboxes are checked, not routines 'assigned' to checkboxes per se.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Assign macro to user form checkbox without running it

    Checking an individual box will not run the macro for you automatically.

    You can create your scripts for each checkbox. And then with a command button, when that is pressed, check if the box is checked and run a particular macro.

    can you post a sample file with with the userform?

  4. #4
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Assign macro to user form checkbox without running it

    That's correct rorya, had a moment of stupidity. Something like this probably will work, right?
    If CheckBox1.Value = True Then Call BFS
    If CheckBox2.Value = True Then Call BHX
    If CheckBox3.Value = True Then Call BRS
    If CheckBox4.Value = True Then Call CWL
    If CheckBox5.Value = True Then Call DUB
    If CheckBox6.Value = True Then Call EDI
    If CheckBox7.Value = True Then Call GLA
    If CheckBox8.Value = True Then Call LBA
    If CheckBox9.Value = True Then Call LCY
    If CheckBox10.Value = True Then Call LGW
    If CheckBox11.Value = True Then Call LHR
    If CheckBox12.Value = True Then Call LPL
    If CheckBox13.Value = True Then Call LUT
    If CheckBox14.Value = True Then Call MAN
    If CheckBox15.Value = True Then Call NCL
    If CheckBox16.Value = True Then Call PIK
    If CheckBox17.Value = True Then Call STN
    If CheckBox18.Value = True Then Call CGI
    Is there a way to make it shorter?

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Assign macro to user form checkbox without running it

    You could remove all the Call keywords.

    Do the routines do similar things? If so, you could have one routine that takes an argument and alters accordingly. If not, you could assign the name of the relevant macro to the Tag property of each control and then use a loop like:

    dim i as long
    for i = 1 to 18
    If Me.Controls("CheckBox" & i).Value = True Then Application.Run Me.Controls("CheckBox" & i).Tag
    Next i
    which is roughly analagous to your original intention of "assigning" a macro? It does assume the routines are all in a normal module.

  6. #6
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Assign macro to user form checkbox without running it

    Do the routines do similar things? If so, you could have one routine that takes an argument and alters accordingly
    Unfortunately, all are doing different things. And honestly, this is the first time that I used a userform. I wasn't really interested in them until now. I did what you suggested and this fixed my issue. Thank you for your help!

+ 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. VBA User Form Issues - Check boxes greyed out after running macro
    By piper9497! in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2019, 05:17 PM
  2. How to assign VBA code to user form controls
    By pedropumpalot in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2015, 08:18 PM
  3. [SOLVED] Grey our a checkbox (not on a user form)
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-05-2014, 04:34 PM
  4. [SOLVED] Running a Copy Row Macro From a User Form (Easy Fix I Think)
    By lsteinbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2013, 04:29 PM
  5. [SOLVED] (updating inventory using user form) : Assign macro to "Çheck Availibility" command button
    By pyol17 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-08-2012, 06:50 AM
  6. User Form During Macro Running
    By mido609 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2012, 06:17 PM
  7. How to: User Form to assign a user defined range to a macro variab
    By TrevTrav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2005, 04:06 PM

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