+ Reply to Thread
Results 1 to 5 of 5

Checkbox if statements

Hybrid View

wayneg Checkbox if statements 10-15-2015, 08:55 AM
gmr4evr1 Re: Checkbox if statements 10-15-2015, 10:03 AM
wayneg Re: Checkbox if statements 10-15-2015, 10:07 AM
wayneg Re: Checkbox if statements 10-15-2015, 10:31 AM
gmr4evr1 Re: Checkbox if statements 10-15-2015, 04:39 PM
  1. #1
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    371

    Checkbox if statements

    PHP Code: 
    Private Sub CheckBox12_Click()

    If 
    CheckBox12.Value True Then CheckBox13.Value False
    If CheckBox12.Value True Then CheckBox1.Value True
    If CheckBox12.Value True Then CheckBox2.Value True
    If CheckBox12.Value True Then CheckBox3.Value True
    If CheckBox12.Value True Then CheckBox4.Value True
    If CheckBox12.Value True Then CheckBox5.Value True
    If CheckBox12.Value True Then CheckBox6.Value True
    If CheckBox12.Value True Then CheckBox7.Value True
    If CheckBox12.Value True Then CheckBox8.Value True
    If CheckBox12.Value True Then CheckBox9.Value True
    If CheckBox12.Value True Then CheckBox10.Value True
    If CheckBox12.Value True Then CheckBox11.Value True

    End Sub 
    Is there a way to make this smaller please, trying to reduce the code and get better at VBA

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Checkbox if statements

    Try this..
    Private Sub CheckBox12_Click()
    
    If CheckBox12.Value = True Then CheckBox13.Value = False And CheckBox1.Value = True _ 
       And CheckBox2.Value = True And CheckBox3.Value = True And CheckBox4.Value = True _ 
       And CheckBox5.Value = True And CheckBox6.Value = True And CheckBox7.Value = True _
       And CheckBox8.Value = True And CheckBox9.Value = True And CheckBox10.Value = True _ 
       And CheckBox11.Value = True
    
    End Sub
    Last edited by gmr4evr1; 10-15-2015 at 10:11 AM. Reason: Prettied up code
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Checkbox if statements

    i tried that, but it didnt work, will try it again, ty......



    i tick the Checkbox12 and it didnt make all the other checkboxes ticked.... will keep trying
    Last edited by wayneg; 10-15-2015 at 10:13 AM.

  4. #4
    Forum Contributor
    Join Date
    04-29-2012
    Location
    nuneaton, England
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Checkbox if statements

    Here is a sample of the file
    Attached Files Attached Files

  5. #5
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Checkbox if statements

    Couldn't get it to work with the first code I posted, but I have an alternative. It might not be much shorter, but it has been tested on your sample file and it works.
    Private Sub CheckBox12_Click()
    
    If CheckBox12.Value = True Then CheckBox1.Value = True
        CheckBox2.Value = True
        CheckBox3.Value = True
        CheckBox4.Value = True
        CheckBox5.Value = True
        CheckBox6.Value = True
        CheckBox7.Value = True
        CheckBox8.Value = True
        CheckBox9.Value = True
        CheckBox10.Value = True
        CheckBox11.Value = True
        
    End Sub
    Private Sub CheckBox13_Click()
    
    If CheckBox13.Value = True Then CheckBox12.Value = False
        CheckBox1.Value = False
        CheckBox2.Value = False
        CheckBox3.Value = False
        CheckBox4.Value = False
        CheckBox5.Value = False
        CheckBox6.Value = False
        CheckBox7.Value = False
        CheckBox8.Value = False
        CheckBox9.Value = False
        CheckBox10.Value = False
        CheckBox11.Value = False
        
    End Sub
    wayneg checkbox-if-statements-form-filter-test.xlsm

+ 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. Select All Checkboxes Checkbox That Also Calls Checkbox Macros
    By Intervigilium in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2015, 06:41 PM
  2. Protect the sheet but the form checkbox still can be change and sort by checkbox
    By carolyn1221 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-19-2014, 01:08 PM
  3. Replies: 0
    Last Post: 04-07-2014, 12:22 PM
  4. Lock cell linked to checkbox when checkbox is ticked
    By simeony003 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2013, 10:08 AM
  5. Replies: 4
    Last Post: 07-22-2013, 01:37 PM
  6. [SOLVED] VBA code to uncheck checkbox 2 & 3 if checkbox 1 is checked
    By hydz1213 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-25-2013, 03:10 AM
  7. [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

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