+ Reply to Thread
Results 1 to 5 of 5

Thread: Show/Hide columns by checkbox and cell text

  1. #1
    Registered User
    Join Date
    11-08-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Red face Show/Hide columns by checkbox and cell text

    Hello, I have been searching on this topic for way too long and decided to just try my luck and see if anyone can help me. I couldn't find any code that matched exactly what I needed and I'm not savvy enough with VBA to figure out how to tailor it to my needs.

    I have a worksheet with 4 checkboxes - Entry, Intermediate, Advanced, and Expert. I want to show/hide columns starting with Column C that have text in Row 3 matching the checkbox. So if Intermediate and Advanced checkboxes are checked, only columns with Intermediate or Advanced in C3 will be visible and columns with Entry or Expert will be hidden.

    Any advice would be greatly appreciated!

    Thanks
    Last edited by ksmoore; 11-09-2010 at 01:22 PM.

  2. #2
    Forum Guru Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,023

    Re: Show/Hide columns by checkbox and cell text

    Without seeing your setup...etc this is the code for the checkbox named entry
    'Code supplied by Simon Lloyd
    '08/11/2010
    'Microsoft Office Help
    Private Sub Entry_Change()
    Dim MyCell As Range, Rng As Range
    Set Rng = Me.Range("D1:G1")
    For Each MyCell In Rng
    If Me.Entry.Value = False And MyCell.Value = Me.Entry.Name Then
    MyCell.EntireColumn.Hidden = False
    End If
    If Me.Entry.Value = True And MyCell.Value = Me.Entry.Name Then
    MyCell.EntireColumn.Hidden = True
    End If
    Next
    End Sub
    Not all forums are the same - seek and you shall find

  3. #3
    Registered User
    Join Date
    11-08-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Show/Hide columns by checkbox and cell text

    Ok, great! It's almost there. With just one checkbox it works perfectly but I attempted to add the additional checkboxes and something is not right. I ran into something similar before and just added a line at the beginning showing all columns, but it is not working properly this time.

    The code I have so far that follows the previous post is:
    Dim MyCell As Range, Rng As Range
    Set Rng = Me.Range("C3:DD3")
    For Each MyCell In Rng
        If Me.CheckBox1.Value = False And MyCell.Value = "Entry" Then
            MyCell.EntireColumn.Hidden = True
        End If
        If Me.CheckBox1.Value = True And MyCell.Value = "Entry" Then
            MyCell.EntireColumn.Hidden = False
        End If
        If Me.CheckBox2.Value = False And MyCell.Value = "Intermediate" Then
            MyCell.EntireColumn.Hidden = True
        End If
        If Me.CheckBox2.Value = True And MyCell.Value = "Intermediate" Then
            MyCell.EntireColumn.Hidden = False
        End If
        If Me.CheckBox3.Value = False And MyCell.Value = "Advanced" Then
            MyCell.EntireColumn.Hidden = True
        End If
        If Me.CheckBox3.Value = True And MyCell.Value = "Advanced" Then
            MyCell.EntireColumn.Hidden = False
        End If
        If Me.CheckBox4.Value = False And MyCell.Value = "Expert" Then
            MyCell.EntireColumn.Hidden = True
        End If
        If Me.CheckBox4.Value = True And MyCell.Value = "Expert" Then
            MyCell.EntireColumn.Hidden = False
        End If
    Next
    End Sub
    Any advice for how to update the sheet on each checkbox selection would be greatly appreciated!

    Thanks again.

  4. #4
    Forum Guru Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,023

    Re: Show/Hide columns by checkbox and cell text

    How about posting the workbook? it'd be a lot easier
    Not all forums are the same - seek and you shall find

  5. #5
    Registered User
    Join Date
    11-08-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Show/Hide columns by checkbox and cell text

    I figured out what I was doing wrong. I needed to make each checkbox an individual function (as the first solution shows), the code I posted would only update with changes to checkbox1. Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0