Results 1 to 2 of 2

Thread: Checkboxes in Excel?

  1. #1

    Thread Starter
    Member dmerchen's Avatar
    Join Date
    Mar 2001
    Location
    Moving Back to Texas
    Posts
    60

    Question Checkboxes in Excel?

    I posted this earlier then changed my profile and poof, everything was gone. Anyway, here we go again. I am working in Excel on some quality documents that I would like to have a little more automated using VBA. I have three colors and two checkboxes. If I put one color in a designated cell then I want one of the checkboxes to become checked. If I put in another color, I would like the other checkbox checked. Any chance that this can be done? Can one checkbox trigger another checkbox on another sheet within the workbook to be checked?
    DMerchen

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    For the first part, you could do something like this:
    VB Code:
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    2.  
    3.     Dim intSelSheet As Integer
    4.  
    5.     ' Check the cell to see if it's fill colour's changed to red,
    6.     ' If so, set the 1st checkbox to on.
    7.     If Range("F3").Interior.ColorIndex = 3 Then
    8.         chkCellColour1.Value = True
    9.         chkCellColour2.Value = False
    10.            
    11.     ' Otherwise, check if it's blue & set the other checkbox
    12.     ' (turning the first checkbox value to off).
    13.     ElseIf Range("F3").Interior.ColorIndex = 5 Then
    14.         chkCellColour1.Value = False
    15.         chkCellColour2.Value = True
    16.  
    17.     ' Finally, if the cell has bot been filled with blue
    18.     ' or red, turn both checkboxes to off.
    19.     Else
    20.         chkCellColour1.Value = False
    21.         chkCellColour2.Value = False
    22.     End If
    23.  
    24. End Sub

    Just change the "Interior.ColorIndex" bit to read "Font.ColorIndex" depending on whether you're checking the fill or the font colour of the cell...

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width