Ask Experts Questions for FREE Help !
Ask
    nurseman3802's Avatar
    nurseman3802 Posts: 1, Reputation: 1
    New Member
     
    #1

    Mar 3, 2010, 07:26 AM
    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.
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Mar 3, 2010, 11:01 AM

    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.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Excel 2003 Macro VBA Hide / Unhide Multiple Sheets [ 5 Answers ]

I'd like to assign a macro button to hide / unhide a range of sheets in a workbook. I have tried various codes from web but have not been successful. (acutally one of the codes worked if I selected 'run' from the macro menu but does not run if button is clicked). I have tried 'recording'...

Excel vba returning values from a sub [ 2 Answers ]

How do I return values from a subroutine in Excel VBA? It appears that I have to "temporarily" store a value elsewhere on the spreadsheet and recover when I return to the main part of the program. Simply the program runs and asks the user to enter data on several forms, but this data has to be...

VBA Access Hide Subform, Box [ 1 Answers ]

Hello all, I'm trying to create an application using access VBA. Unfortunately, I'm a novice programming in VBA. I'd like to know the VBA code to hide and show a subform or a box created in a form. Thanks Sean

VBA and Excel for office97 [ 1 Answers ]

I have created a form in Excel using VBEditor in Excel and want to use the form to transfer data to Excel spreadsheet. I create an Excel file. Whenever the file is opened I want the form to load automatically. Then I use the form to enter data in specified cells. When I am through posing the data,...


View more questions Search