+ Reply to Thread
Results 1 to 8 of 8

Allow button code execution based on a checkbox value.

  1. #1
    Registered User
    Join Date
    01-14-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    14

    Allow button code execution based on a checkbox value.

    Hi all,

    Stupid code to write, may be too easy but just not clicking through.

    The sheet has multiple buttons and associated checkboxes (say, btn1, chkbx1, btn2, chkbx2, btn3, chkbx3). If a button in clicked and code executes successfully, the checkbox corresponding to it updates.
    I want to do is, user cannot click on btn2, if chk1 is not checked and btn3, if chk2 and 1 are not checked. ideas?
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Allow button code execution based on a checkbox value.

    Start with all commandbuttons except the first disabled.
    Use the click event of the check box to enable or disable the associated next commandbutton, if the user can click the check boxes.
    Please Login or Register  to view this content.
    For the later buttons, etc.
    Please Login or Register  to view this content.
    IF you are only doing the checkboxes in code, after you check the checkbox, enable the next available commandbutton, like:
    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 02-13-2014 at 11:57 AM.

  3. #3
    Registered User
    Join Date
    01-14-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Allow button code execution based on a checkbox value.

    Hey, thanks for the reply. I do not want to enable/disable the buttons but rather pop a message and make the rest of the code not executable. Does it makes sense!

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Allow button code execution based on a checkbox value.

    Sure - just put in a lot of conditionals in your code, like

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-14-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Allow button code execution based on a checkbox value.

    Thanks Bernie, Instead for writing it for every checkbox, I am trying to create a function passing Boolean value. so, if its a true, the rest of the code does not excute and exits. Ideas?

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Allow button code execution based on a checkbox value.

    One way is to split the code into blocks.You could use code like this: first declare a global boolean for control
    Please Login or Register  to view this content.
    Then, at the top of every section of code, use code like

    Please Login or Register  to view this content.
    ' And wherever you have code that sets a checkbox, use this as the next line

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-14-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Allow button code execution based on a checkbox value.

    See the code below. When I run this, for the first button it should not pop up any error message because the folders are already created, however it does because the conidtions for the second button are met in a way that it messes the first one. I am not in my best form today, lol

    Edited: See the pic also:

    tf.png
    HTML Code: 
    Last edited by rajwar; 02-13-2014 at 01:04 PM.

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: Allow button code execution based on a checkbox value.

    I really can't comment on what is going wrong based on a code snippet, except to say that when you are setting DisableFolderConfirm you can combine the other elements instead of checking that value later in an IF structure:
    Please Login or Register  to view this content.

+ 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. [SOLVED] VBA code to populate checkbox with tick upon initialization based on Cell value being Yes
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2013, 09:58 AM
  2. Macro or VBA code to update non primary sheets based on checkbox
    By jbpar5s in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2013, 06:19 PM
  3. [SOLVED] How do I change a checkbox to unchecked without running the code within the checkbox
    By jsunnb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2012, 09:28 PM
  4. Checkbox choices that run code on clicking command button
    By Sharky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2007, 05:30 PM
  5. 2pcs of code, a button & a checkbox
    By Lynda in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-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