+ Reply to Thread
Results 1 to 11 of 11

Please Help - Hiding/Unhiding code - MACRO/VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    03-27-2017
    Location
    Manila, Philippines
    MS-Off Ver
    2010
    Posts
    64

    Please Help - Hiding/Unhiding code - MACRO/VBA

    Hi All,

    I have no background nor proper training on handling VBA/Macros but sooner I would like to learn at least the basic of it. I am thinking to create a template that would help me navigating on my report efficiently, can anyone could please help me create a simple macro that control (hid/unhide) tabs on my excel – then probably I can use it to pattern on others.

    Ideas:
    Control Tab – this contains shapes which I would like to assign a macro when clicked. They are Week 1, 2, 3, 4, Hide All, Dashboard, Report and Tally.

    The idea is to show ONLY the tabs that I would like to see on my workbook.

    Expected Outcomes:
    1. When I clicked WEEK 1, it will only show tabs W1-1, W1-2, W1-3, W1-4 and W1-5
    2. When I clicked WEEK 2, it will only show tabs W2-1, W2-2, W2-3, W2-4 and W2-5
    3. When I clicked WEEK 3, it will only show tabs W3-1, W3-2, W3-3, W3-4 and W3-5
    4. When I clicked WEEK 4, it will only show tabs W4-1, W4-2, W4-3, W4-4 and W4-5
    5. When I clicked HIDE ALL, it will hide all tabs EXCEPT the CONTROL tab
    6. When I clicked DASHBOARD, it will only show the DASHBOARD and the CONTROL tabs
    7. When I clicked REPORT, it will only show the REPORT and the CONTROL tabs
    8. When I clicked TALLY, it will only show the TALLY and the CONTROL tabs

    By the way, I am using excel 2016

    Kindly see the sample workbook I’ve attached for your reference.

    Thank you all in advance…I would take it as a first step to a more complicated VBA functions.

    Appreciate your help.

    Dy
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    03-27-2017
    Location
    Manila, Philippines
    MS-Off Ver
    2010
    Posts
    64

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    I forgot, on the Expected Outcomes 1-4, it should also show the CONTROL tab and the corresponding weeks' tabs.

  3. #3
    Forum Contributor
    Join Date
    06-07-2016
    Location
    Manila
    MS-Off Ver
    365
    Posts
    292

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    Hi dy137,

    you can try this.

    Dim sh As Worksheet
    
        For Each sh In Sheets
            If sh.Name <> "Control" And sh.Name <> "W1-1" And sh.Name <> "W1-2" And sh.Name <> "W1-3" And sh.Name <> "W1-4" And sh.Name <> "W1-5" Then
                sh.Visible = xlSheetVeryHidden
            End If
        Next sh
    You should place that under the Wk1 button, then just modify it with the other buttons.

  4. #4
    Registered User
    Join Date
    03-27-2017
    Location
    Manila, Philippines
    MS-Off Ver
    2010
    Posts
    64

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    Quote Originally Posted by aarona View Post
    Hi dy137,

    you can try this.

    Dim sh As Worksheet
    
        For Each sh In Sheets
            If sh.Name <> "Control" And sh.Name <> "W1-1" And sh.Name <> "W1-2" And sh.Name <> "W1-3" And sh.Name <> "W1-4" And sh.Name <> "W1-5" Then
                sh.Visible = xlSheetVeryHidden
            End If
        Next sh
    You should place that under the Wk1 button, then just modify it with the other buttons.



    Hi aarona,

    Thanks for your help ..it is a good start for me...a little bit of favor...can you also create one for HIDE ALL - from there, I can already start playing around with the code.. Thanks

  5. #5
    Forum Contributor
    Join Date
    06-07-2016
    Location
    Manila
    MS-Off Ver
    365
    Posts
    292

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    Sure, here

    
    Dim sh As Worksheet
    
        For Each sh In Sheets
        
            If sh.Name <> "Control" Then
                sh.Visible = xlSheetHidden
            End If
        Next sh

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,227

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    Hi Dy,

    Here is your workbook back with all the code you asked for. I also added a sub called UnHideAll. You should add the Dashboard sheet when you click on the individual weeks so you can then go to the other subs. BUT - you didn't ask for that.

    VBA for Sheets Hide.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Registered User
    Join Date
    03-27-2017
    Location
    Manila, Philippines
    MS-Off Ver
    2010
    Posts
    64

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    Hello MarvinP,

    This is great! you've made this easy for me..

    I have a concern though, when I clicked Week 1 for example, I am already lost - I cannot go back to the control tab...apologies, I actually have added this requirement on my second reply...

    Here's how it should work, When WEEK 1,2,3 or 4 is clicked, it should show its corresponding tabs plus the CONTROL tab...this should also apply to all macro

  8. #8
    Registered User
    Join Date
    03-27-2017
    Location
    Manila, Philippines
    MS-Off Ver
    2010
    Posts
    64

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    I could probably look at how you did it in other tab and add it...I may be asking too much

    Thanks MarvinP! Appreciate it

  9. #9
    Registered User
    Join Date
    03-27-2017
    Location
    Manila, Philippines
    MS-Off Ver
    2010
    Posts
    64

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    Quote Originally Posted by MarvinP
    You should add the Dashboard sheet when you click on the individual weeks so you can then go to the other subs. BUT - you didn't ask for that.
    Something I realized. You're right! That should also be part of it..

    Can we make the CONTROL tab available for ALL then? - I'm not sure If I can do this without that much knowledge in VBA but I will try to pattern with your work.. :/

  10. #10
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,227

    Re: Please Help - Hiding/Unhiding code - MACRO/VBA

    OK - done!

    VBA for Sheets Hide 2.xlsm

    Hope that helps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to Add and Delete Row (by unhiding and hiding)
    By Mo_Blues in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-04-2015, 05:36 AM
  2. hiding unhiding rows macro hierarchy
    By dgibney in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 11-19-2014, 01:44 PM
  3. [SOLVED] Changes & creation of Code for hiding & unhiding columns & Sheet
    By paradise2sr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2013, 09:14 AM
  4. [SOLVED] Need help - VBA code for hiding / unhiding rows through Option Button
    By gm2612 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2013, 03:26 AM
  5. VBA code in HIDING & UNHIDING row if value is zero
    By znalron@yahoo.com in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-26-2013, 11:53 PM
  6. Excel 2007 Hiding/Unhiding Worksheets Using Code
    By mab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2010, 11:44 AM
  7. error comes in my code for hiding/unhiding
    By ss_bb_24 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2008, 05:09 AM

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