+ Reply to Thread
Results 1 to 3 of 3

Hide/Unhide Multiple Checkboxes

Hybrid View

LampCommandr Hide/Unhide Multiple... 06-29-2011, 05:45 PM
Leith Ross Re: Hide/Unhide Multiple... 06-29-2011, 06:02 PM
LampCommandr Re: Hide/Unhide Multiple... 06-30-2011, 09:35 AM
  1. #1
    Registered User
    Join Date
    05-12-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    42

    Hide/Unhide Multiple Checkboxes

    Hey folks,

    I currently have a check box that when clicked should hide/unhide a column and all checkboxes in the column (50 in total).

    The code that I’m using is as follows:

    Sub CheckBox_ClientType()
    
    Select Case Worksheets("Client Requests").CheckBoxes("CheckBox_ClientType").Value
    
    Case xlOn
    
        Range("Client_Request").EntireColumn.Hidden = False
    
        ActiveSheet.CheckBoxes("ClientRequest_1").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_2").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_3").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_4").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_5").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_6").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_7").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_8").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_9").Visible = True
        ActiveSheet.CheckBoxes("ClientRequest_10").Visible = True
    
    Case xlOff
    
        Range("Client_Request").EntireColumn.Hidden = True
    
        ActiveSheet.CheckBoxes("ClientRequest_1").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_2").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_3").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_4").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_5").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_6").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_7").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_8").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_9").Visible = False
        ActiveSheet.CheckBoxes("ClientRequest_10").Visible = False
    
    End Select
    
    End Sub
    Is there a more practical way of coding this to reference all 50 checkboxes without having to reference each on individually?
    Last edited by LampCommandr; 06-30-2011 at 09:35 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Hide/Unhide Multiple Checkboxes

    Hello LampCommandr,

    You do it this way.

    Sub Macro1A()
    
    Dim ChkBox As Object
    
    Select Case Worksheets("Client Requests").CheckBoxes("CheckBox_ClientType").Value
    
    Case xlOn
    
        Range("Client_Request").EntireColumn.Hidden = False
    
        For Each ChkBox In ActiveSheet.CheckBoxes
          If ChkBox.Name Like "ClientRequest_*" Then
             ChkBox.Visible = True
          End If
        Next ChkBox
    
    Case xlOff
    
        Range("Client_Request").EntireColumn.Hidden = True
    
        For Each ChkBox In ActiveSheet.CheckBoxes
          If ChkBox.Name Like "ClientRequest_*" Then
             ChkBox.Visible = False
          End If
        Next ChkBox
    
    End Select
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-12-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Hide/Unhide Multiple Checkboxes

    Brilliant! Thanks Leith!

+ 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