Consulting

Results 1 to 6 of 6

Thread: Conditional hiding of rows

  1. #1

    Conditional hiding of rows

    Could you help me with the VBA syntax to accomplish the following:

    • On Sheet1 there will be an option button, with the instruction "click here if this is a multilevel calculation"
    • If the user clicks the option button, rows A5:A8 in Sheet2 are unhidden. Otherwise they remain hidden
    Thanks.

    KG

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try the following
    MD


    Sub Macro1()
        Sheets("Sheet2").Rows("5:8").Hidden = False
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    if this was meant to be a macro assigned to the option button, it did not do the trick for me.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try setting up a second option button. The following works for me.


    Private Sub OptionButton1_Click()
        Macro1
    End Sub
    
    Private Sub OptionButton2_Click()
        Macro2
    End Sub
    
    Sub Macro1()
        Sheets("Sheet2").Rows("5:8").Hidden = False
    End Sub
    
    Sub Macro2()
        Sheets("Sheet2").Rows("5:8").Hidden = True
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    If it's an option, I personally prefer to use a checkbox, since you can't "unselect" and option button unless you have a second one.

    With a checkbox, you can put all your code in one sub:

    Private Sub CheckBox1_change()
         Select Case CheckBox1.Value
             Case Is = True
                 Sheets("Sheet2").Rows("5:8").Hidden = False
             Case Is = False
                 Sheets("Sheet2").Rows("5:8").Hidden = True
         End Select
     End Sub
    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Agreed, The code will only run once with a single option button.
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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