Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Show hide sheets excel in VBA (https://www.askmehelpdesk.com/showthread.php?t=453819)

  • Mar 3, 2010, 07:26 AM
    nurseman3802
    show hide sheets excel in VBA
    I am currently working on a spreadsheet that tracks data for about 40 employees. As you can tell the worksheet tabs become quite cumbersome to sort through, so I was wondering if I could write code to assign each tab (worksheet) to an employee. I thought that If I could create a main page with a button for each employee, then I could just click the button to go right to their worksheet, all while keeping the other tabs (worksheets) hidden. I tried the following formula and instructions but don't understand what it means when it says "edit the commandbutton10 to match the numeric value of your new button so it works....edit all references" I Shouldn't the code just be written specifially to the button created? Any help would be appreciated.
    1. Use the Control Toolbox toolbar to create a Command Button.
    2. Right-click the new button, and select Properties
    3. Put a new CAPTION called TURN FEB OFF
    4. Close the Properties Window
    5. Now, let's have some fun: Right-click the new button again and select View Code
    6. A blinking cursor is ready for your new code. Add the code below:
    Code:


    Application.ScreenUpdating = False
    If CommandButton10.Caption = "TURN FEB OFF" Then
    CommandButton10.Caption = "TURN FEB ON"
    CommandButton10.ForeColor = &HFFFF&
    Sheets("FEB").Visible = False
    Else: CommandButton10.Caption = "TURN FEB OFF"
    CommandButton10.ForeColor = &HC0&
    Sheets("FEB").Visible = True


    7. Edit the CommandButton10 to match the numeric value of your new button so it works... edit all the references.
    8. Now click the Exit Design Mode button on the Control Toolbox toolbar.
    9. Try clicking your new button

    If this works to your satisfaction, edit the VBA above to do all the sheets, or make individual buttons. Your call.
  • Mar 3, 2010, 11:01 AM
    JBeaucaire

    When you add a new button, then right-click it and VIEW CODE, you will find yourself in the VBEditor inside a new commandbutton code sub. The sub will have a specific name matching the button number you just created.

    You need to add code into that sub and adjust the CommandButton10 to CommandButton13 or CommandButton26... whatever the number is.

    Each line of code you put in that sub would need to be edited, along with the Sheet Tab name you want hidden/unhidden.

    ==========
    Hiding and unhiding sheets is really not necessary. You can use Excel's Hyperlink feature to jump to any one sheet. I've used this in the past to create a front sheet "menu"... a sheet with nothing more than links to all the other sheets. Clicking a hyperlinked cell jumps to Sheet40.

    On every other sheet is the same Hyperlink that jumps back to the front sheet menu. So clicking from anyone sheet to another is always two fast clicks.

    This would be FAR less maintenance.

  • All times are GMT -7. The time now is 12:37 PM.