+ Reply to Thread
Results 1 to 6 of 6

Use VBA to change worksheet tab color based on ActiveX checkbox values

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Use VBA to change worksheet tab color based on ActiveX checkbox values

    Hello -

    I would like to use VBA to change the worksheet tab color based on ActiveX checkbox values. I have 10 ActiveX checkboxes on one worksheet. When one of the boxes is checked, I want the worksheet tab color to change to yellow. When all are checked, I would like the worksheet tab to change to green. When none are checked, I would like the worksheet tab to remain red.

    What is the best way to do this?

    Thank you!
    Last edited by penny; 01-19-2015 at 11:29 AM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Use VBA to change worksheet tab color based on ActiveX checkbox values

    Sub CheckStatus()
    Dim Ck As Object
    Dim N As Long
    
    For Each Ck In ActiveSheet.OLEObjects
    If TypeName(Ck.Object) = "CheckBox" Then
        If Ck.Object.Value Then
            N = N + 1
        End If
    End If
    Next
    
    Select Case N
        Case 0
            ActiveSheet.Tab.ColorIndex = 3
        Case 1 To 9
            ActiveSheet.Tab.ColorIndex = 6
        Case 10
            ActiveSheet.Tab.ColorIndex = 4
    End Select
    
    End Sub
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Re: Use VBA to change worksheet tab color based on ActiveX checkbox values

    Thank you for the help, Tinbendr. I am unable to get this code to work. I have copied and pasted it into the code of the worksheet. Does it have anything to do with my checkboxes being labeled as "CheckBox1", "CheckBox2", etc.?

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Use VBA to change worksheet tab color based on ActiveX checkbox values

    Go to Developer tab. Click Design. Double click on each button. This will generate a click event. In each event type the name of the macro. Turn design mode off. Then as you click each checkbox, the code will run and change to tab color as required. I thought it didn't work at first either, but you have to get off the tab to really see the color.

  5. #5
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Re: Use VBA to change worksheet tab color based on ActiveX checkbox values

    Thank you! I added the macro to each click event. It still wasn't working. I realized I had all of the checkboxes grouped. Once I removed the grouping, the code worked great.

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Use VBA to change worksheet tab color based on ActiveX checkbox values

    For checkboxes in Groups
    Sub CheckStatus()
    Dim WS As Worksheet
    Dim N As Long
    Dim Grp As Shape
    Dim Ck As Shape
    
    Set WS = ActiveSheet
    
    For Each Grp In WS.Shapes
        If Grp.Type = msoGroup Then
            For Each Ck In Grp.GroupItems
            If TypeName(Ck.OLEFormat.Object.Object) = "CheckBox" Then
                If Ck.OLEFormat.Object.Object.Value Then
                    N = N + 1
                End If
            End If
            Next
        End If
    Next
    
    Select Case N
        Case 0
            ActiveSheet.Tab.ColorIndex = 3
        Case 1 To 9
            ActiveSheet.Tab.ColorIndex = 6
        Case 10
            ActiveSheet.Tab.ColorIndex = 4
    End Select
    
    End Sub

+ 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] Easy Macro needed to change some, not all, activeX checkbox to False or True
    By caliskier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2014, 12:51 PM
  2. Replies: 5
    Last Post: 05-22-2013, 10:24 PM
  3. Using ActiveX CheckBox Control to make a cell change colour and clear values
    By drmit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2012, 04:18 AM
  4. Hide ActiveX Checkbox on worksheet
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2011, 04:46 PM
  5. VBA code to change PivotTable selections, based on ActiveX CheckBoxes on a worksheet.
    By BasicElement in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-29-2009, 05:10 AM

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