+ Reply to Thread
Results 1 to 4 of 4

Codepended Check Boxes

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    161

    Codepended Check Boxes

    Hi all,

    I have 2 check boxes in sheet. Each of them controls separate cell. If I check Box1, cell B12 will show "True". If I check Box2, cell B14 will show "True".
    I need when I check one of the boxes, the other one automatically to be unchecked. In same time only one box can be checked.

    Below is my code. There is conflict in it and does not work properly.

    Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
            Range("B12").Value = True
            CheckBox2.Value = False
            End If
    If CheckBox1.Value = False Then
            Range("B12").Value = False
            CheckBox2.Value = True
            End If
    End Sub
    
    Private Sub CheckBox2_Click()
    If CheckBox2.Value = True Then
            Range("B14").Value = True
            CheckBox1.Value = False
            End If
    If CheckBox1.Value = False Then
            Range("B14").Value = False
            CheckBox1.Value = True
            End If
    End Sub
    Any ideas how to fix this?

    Thank you

    Igor

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Codepended Check Boxes

    Hi Igor,

    If I understood you well, you are using ActiveX Cheeckboxes, and want to have always one checked and the other not (may be not in initial state, but once one is checked first time).
    In this case you probably do not really need two checkboxes, one would be enough. but:

    Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
            Range("B12").Value = True
            CheckBox2.Value = False
            Range("B14").Value = False
            End If
    If CheckBox1.Value = False Then
            Range("B12").Value = False
            CheckBox2.Value = True
            Range("B14").Value = True
            End If
    End Sub
    and similar code, but with opposite references for the second one
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Codepended Check Boxes

    But if you allow 3 options any time:
    - both false
    - 1st true 2nd false
    - 1st false 2nd true
    try:
    Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
            Range("B12").Value = True
            CheckBox2.Value = False
            Range("B14").Value = False
            End If
    If CheckBox1.Value = False Then
            Range("B12").Value = False
            End If
    End Sub
    
    Private Sub CheckBox2_Click()
    If CheckBox2.Value = True Then
            Range("B14").Value = True
            CheckBox1.Value = False
            Range("B12").Value = False
            End If
    If CheckBox2.Value = False Then
            Range("B14").Value = False
            End If
    End Sub
    or shorter:
    Private Sub CheckBox1_Click()
    Range("B12").Value = CheckBox1.Value
    If CheckBox1.Value Then
       CheckBox2.Value = False
       Range("B14").Value = False
    End If
    End Sub
    (and similar but opposite for second one)
    Last edited by Kaper; 01-28-2016 at 09:14 AM. Reason: added short version

  4. #4
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    161

    Re: Codepended Check Boxes

    Hi Kaper,

    THATS PERFECT!!!!!
    for me works the second option.

    Thank you a lot!!!.
    Igor

+ 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. Check boxes that delete other check boxes and change the color of another cell.
    By nhamhamilton in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-29-2014, 02:40 PM
  2. [SOLVED] Coding Yes/No option buttons to not allow check boxes or require check boxes
    By HeyInKy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2014, 11:32 PM
  3. [SOLVED] How to Count Check Boxes and count the total number of boxes checked
    By t04904 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2013, 11:45 AM
  4. Replies: 1
    Last Post: 05-23-2013, 10:42 AM
  5. Automatically check one or more check boxes when a parent check box is manually checked
    By Steverizer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-28-2013, 01:56 PM
  6. I need a code for presence check to check multiple text boxes and combo boxes
    By Lee_wwfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2013, 01:53 PM
  7. Automatic setting of check boxes based on other check boxes?
    By ArchiveMike in forum Excel General
    Replies: 5
    Last Post: 07-31-2012, 09:43 AM

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