+ Reply to Thread
Results 1 to 26 of 26

vba code for hide/unhide tabs based on color

  1. #1
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    vba code for hide/unhide tabs based on color

    My questions is how to hide/unhide tabs based on tab color. i right clicked on tab and selected view code and inserted the code to change the color of the tab based on a couple cells criteria. what I need is to add code to hide/unhide each sheet when tab color is true.

    Be specific. the name of my file is master copy ....... In this file I have approx. 15 sheets, with the tabs having specific name IE labor report, totals ect. I then copy and paste and rename the file for each specific jobname, We are a small const. company, into a shared dropbox file. The file tracks labor and material for each specific job. Not every job will use each tab within the file. Also, sometimes a tab or sheet will not be activated until a later time. IE my materials recap sheet doesn't change colors until an actual invoice for materials is posted, likewise my labor report is not activated until labor is reported.

    Any help would be greatly appreciated. I have tried to google this many times. However, I don't not understand code very well and don't understand exactly what info is needed in code.

    Thanks
    Todd

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code for hide/unhide tabs based on color

    You can have multiple cases if you want

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    My tabs are green for each one except totals (Red). Can I put this under my other code. Do I type in exactly as you have it wriiten.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code for hide/unhide tabs based on color

    Yes. You will need to find out what the color number is for green.

  5. #5
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    rivate Sub Worksheet_Change(ByVal Target As Range)
    If Range("C43").Value > 0 Then
    Me.Tab.ColorIndex = 4
    Else
    Me.Tab.ColorIndex = xlColorIndexNone
    End If
    End Sub

    Sub Hide_SheetsbyColor()
    Dim ws As Worksheet

    For Each ws In Worksheets
    Select Case ws.Tab.Color
    Case Is = 255 'red
    ws.Visible = xlSheetVisible
    Case Is = 65535 'yellow
    ws.Visible = xlSheetHidden
    End Select
    Next ws
    End Sub
    End Sub

    Here is what I have. Also how do I get hidden tab back when needed?

  6. #6
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Stnkynts was wondering if you had a chance to look at what I have and have a fix. I am posting another tab code I have.


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("C40").Value > 0 Then
    Me.Tab.ColorIndex = 4
    Else
    If Range("I44").Value <> 0 Then
    Me.Tab.ColorIndex = 4
    Else
    Me.Tab.ColorIndex = xlColorIndexNone
    End If
    End If
    End Sub

    thanks

  7. #7
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    was wondering if anybody may have a fix for this issue

    thanks

  8. #8
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code for hide/unhide tabs based on color

    The code you provided is part of the Worksheet_Change event which is different than the Subroutine I provided. They cannot be merged together like you have. You would need to insert a new module and add it there. Google search creating a macro in VBA for more information.

    In addition, getting the tab back is easy. I just need parameters to determine when the tab should show.

  9. #9
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Stnkynts I googled what you said to, but my lack of knowledge doesn't allow me to understand what is needed. as far as getting tab back, I need to be able to enter info on a hidden tab at a later date. IE if I open job file and enter all info I have at that time, then for some reason we order material which is on a hidden tab or enter labor time I would need to be able to retrieve hidden tab make it active based code I sent previously. Would it be easier if I included my whole file so you can see what is going on.

  10. #10
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Was wondering if anybody else had an answer to this. Thanks

  11. #11
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: vba code for hide/unhide tabs based on color

    What is the point of changing the tab color if you're hiding the sheet?

    Why don't you just hide the sheet if C40 > 0?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: vba code for hide/unhide tabs based on color

    What is the point of changing the tab color if you're hiding the sheet?

    Why don't you just hide the sheet if C40 > 0?

  13. #13
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code for hide/unhide tabs based on color

    You can submit your workbook if you want. Just make sure it is very clear what is going on and what you want to have happen.

  14. #14
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Quote Originally Posted by Solus Rankin View Post
    What is the point of changing the tab color if you're hiding the sheet?

    Why don't you just hide the sheet if C40 > 0?
    I want the tab to change colors once it becomes active. I may hide the sheet at first, but later on I may need the sheet to be unhidden and activated. Therefore, I would want the tab to change colors.

  15. #15
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: vba code for hide/unhide tabs based on color

    You can submit your workbook if you want. Just make sure it is very clear what is going on and what you want to have happen.
    Please attach your workbook as an example so edits can be made.

  16. #16
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    I have tried to attach workbook by reading the rules section. do not see a button with a paperclip anywhere.

  17. #17
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: vba code for hide/unhide tabs based on color

    Click the 'Go Advanced' button below.

  18. #18
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Test copy for VBA request.xlsm

    here is example of my file I have input a little info like job name and # the green highlighted tabs have been activated because I either ordered material or going to order material. The totals is red because of the note on the bottom. I would like to hide all the other tabs for use at a later date. I may or may not need them, but would like to be able to unhide them if I need to input info at a later date.

    Thanks for you help

  19. #19
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: vba code for hide/unhide tabs based on color

    Solus edit.xlsm I'm not completely sure what you're going for yet, but lets see if this gets you close.

  20. #20
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    I opened up your file it doesn't appear different than mine. This may help

    1. open up new job, input all known data at this point
    2. if tab is activate with current info it stays activated and all other tabs are hidden
    3 at a later time in the day or anytime after job is opened and I want to add data to any of the current or hidden tabs, I want to be able to unhide tabs and make active.

    The reason I want to be able to do this is to save time scrolling back and forth across the page or right clicking and finding page. If this is not available then I have what I have.

    Thanks Solus

  21. #21
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: vba code for hide/unhide tabs based on color

    Did you see the hide and unhide buttons on the Job Totals tab?

  22. #22
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Yes works great. Thanks for you help.

  23. #23
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Solus It works great. However, How did you insert the hide/unhide buttons. I would like to maybe move them to the Labor report sheet. Want to test out different places.

    Thanks

  24. #24
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Also, Currently have some jobs opened and would like to add this feature to those files.

  25. #25
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: vba code for hide/unhide tabs based on color

    I added activeX buttons to the tab using the developers tab --> Insert --> ActiveX Controls --> Command button. I double clicked the button (while in design mode) to open the code window for the button. Then I pasted the code into the created button click event.

    Here is a link to enable the developers tab http://msdn.microsoft.com/en-us/library/bb608625.aspx

  26. #26
    Registered User
    Join Date
    03-12-2014
    Location
    missouri
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: vba code for hide/unhide tabs based on color

    Thanks Solus Works Great. Exactly what I needed.

+ 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. Hide / unhide cells based on a VBA code
    By Metalgijs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 11:21 AM
  2. Macro that will hide/unhide sheets based on tab color.
    By Rixonomic in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-11-2012, 02:07 PM
  3. Using checkboxes on summary sheet to name tabs and hide/unhide tabs
    By eew2201 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2012, 06:13 PM
  4. Hide/unhide Tabs by color
    By angeljdiez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2012, 03:11 AM
  5. Hide Rows in Index Sheet Based On Color Of Other Tabs
    By mgaworecki in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-20-2007, 10:58 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