+ Reply to Thread
Results 1 to 4 of 4

How do I change a checkbox to unchecked without running the code within the checkbox

  1. #1
    Registered User
    Join Date
    08-07-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    How do I change a checkbox to unchecked without running the code within the checkbox

    I have a macro I've written that has a checkbox on a userform. I'd like that checkbox to either start out as checked or not checked, depending on certain logic. I also have code that runs when I use the mouse to click the checkbox and switch it between checked and unchecked. The problem is, when I try to just change the value of the checkbox, it always runs the code within the checkbox, which I don't want unless it is clicked with a mouse.

    Here is a simplified version of my code (to get my point across)

    Sub test()
    If Range("K4") = "N/A" Then
    UserForm1.CheckBox1 = True 'Only want value changed, not the macro run as if the checkbox was clicked
    Else
    UserForm1.CheckBox1 = False
    End If
    End Sub




    'Code within UserForm
    Private Sub CheckBox1_Click()
    If CheckBox1 Then
    TestValue = 42
    End IF
    End Sub

    And help would be much appreciated, it's really frustrating.
    Last edited by jsunnb; 09-27-2012 at 12:47 PM.

  2. #2
    Registered User
    Join Date
    11-25-2008
    Location
    Poland
    MS-Off Ver
    MSO 2K3, 2K10
    Posts
    84

    Re: How do I change a checkbox to unchecked without running the code within the checkbox

    In UserForm1 module:
    Please Login or Register  to view this content.
    and in other module:
    Please Login or Register  to view this content.
    Artik

  3. #3
    Registered User
    Join Date
    08-07-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: How do I change a checkbox to unchecked without running the code within the checkbox

    Thank you very much, that worked perfectly.
    Also, you taught me how to use something I've never been able to get to work before either, public variables.

    Thank you again.
    Last edited by jsunnb; 09-27-2012 at 12:45 PM.

  4. #4
    Registered User
    Join Date
    11-25-2008
    Location
    Poland
    MS-Off Ver
    MSO 2K3, 2K10
    Posts
    84

    Re: How do I change a checkbox to unchecked without running the code within the checkbox

    jsunnb, be careful. Public variables that are declared in a standard module, live until you close the program. Public variables that are declared in a class module (UserForm1), they live until unloading form.

    Artik

+ 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