+ Reply to Thread
Results 1 to 5 of 5

Option Button that shows/hide certain cells

Hybrid View

  1. #1
    Registered User
    Join Date
    04-12-2012
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Option Button that shows/hide certain cells

    Hey-

    I need to create 2 option buttons one that shows cells F3 and G3 all the way down and then another one that hides F3 and G3 and down?

    Coding suggestions?

  2. #2
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: Option Button that shows/hide certain cells

    DoubleA,

    Considering that is not possible to Hide a cells range, i just make the trick code above that paint the text in white, so the text become "invisible", and the other button that paint the text in black.

    Hope that can help:

    Sub Hide()
    
    ActiveSheet.Range("F3:G3", ActiveSheet.Range("F3:G3").End(xlDown)).Select
        With Selection.Font
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = 0
        End With
    
    ActiveSheet.Range("A2").Select
    
    End Sub
    
    Sub UnHide()
    
    ActiveSheet.Range("F3:G3", ActiveSheet.Range("F3:G3").End(xlDown)).Select
        With Selection.Font
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
        End With
    
    ActiveSheet.Range("A2").Select
    
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Option Button that shows/hide certain cells

    Like this:

    Sub Hide()
    Dim Ws1 As Worksheet
    Dim Ws2 As Worksheet
    Dim Rng As String
    
    Set Ws1 = ActiveSheet
    Set Ws2 = Sheets("Hidden Sheet")
    
    Rng = Ws1.Range("F3:G3", Ws1.Range("F3:G3").End(xlDown)).Address
    
    Ws2.Range(Rng).Value = Ws1.Range(Rng).Value
    
    Ws1.Range(Rng).ClearContents
    End Sub
    
    Sub UnHide()
    Dim Ws1 As Worksheet
    Dim Ws2 As Worksheet
    Dim Rng As String
    
    Set Ws1 = ActiveSheet
    Set Ws2 = Sheets("Hidden Sheet")
    
    Rng = Ws2.Range("F3:G3", Ws2.Range("F3:G3").End(xlDown)).Address
    
    Ws1.Range(Rng).Value = Ws2.Range(Rng).Value
    
    Ws2.Range(Rng).ClearContents
    End Sub
    Mind you, you would need to add a sheet with the name "Hidden Sheet" and hide it.
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  4. #4
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Option Button that shows/hide certain cells

    Another way would be to move the contents of the cells to a hidden sheet and then moving them back with the other button.

  5. #5
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Option Button that shows/hide certain cells

    Small change in case you have empty cells in the middle:

    Sub Hide()
    Dim Ws1 As Worksheet
    Dim Ws2 As Worksheet
    Dim Rng As String
    Dim n As Long
    
    Set Ws1 = ActiveSheet
    Set Ws2 = Sheets("Hidden Sheet")
    n = Ws1.Range("F" & Ws1.Rows.Count).End(xlUp).Row
    If n < Ws1.Range("G" & Ws1.Rows.Count).End(xlUp).Row Then
        n = Ws1.Range("G" & Ws1.Rows.Count).End(xlUp).Row
    End If
    
    Rng = Ws1.Range("F3:G3", Ws1.Range("G" & n)).Address
    
    Ws2.Range(Rng).Value = Ws1.Range(Rng).Value
    
    Ws1.Range(Rng).ClearContents
    End Sub
    
    Sub UnHide()
    Dim Ws1 As Worksheet
    Dim Ws2 As Worksheet
    Dim Rng As String
    Dim n As Long
    
    Set Ws1 = ActiveSheet
    Set Ws2 = Sheets("Hidden Sheet")
    n = Ws2.Range("F" & Ws2.Rows.Count).End(xlUp).Row
    If n < Ws2.Range("G" & Ws2.Rows.Count).End(xlUp).Row Then
        n = Ws2.Range("G" & Ws2.Rows.Count).End(xlUp).Row
    End If
    
    Rng = Ws2.Range("F3:G3", Ws2.Range("G" & n)).Address
    
    Ws1.Range(Rng).Value = Ws2.Range(Rng).Value
    
    Ws2.Range(Rng).ClearContents
    End Sub

+ 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.6.0 RC 1