+ Reply to Thread
Results 1 to 13 of 13

hide tab if cell equals "Yes"

  1. #1
    Registered User
    Join Date
    09-18-2017
    Location
    San Francisco
    MS-Off Ver
    2013
    Posts
    39

    hide tab if cell equals "Yes"

    Hi,
    I want to hide a tab based on a value in a different tab.
    For example, if on the Dashboard cell D8 = "Yes" or "No" then hide the tab named "Audit".
    If D8 has anything else but "Yes" or "No", then leave the tab visible.

    Can anyone help with the code?

    Thanks!
    Last edited by alisachsf; 09-03-2019 at 05:51 PM.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: hide tab if cell equals "Yes"

    How about
    Please Login or Register  to view this content.
    This needs to go in the Dashboard sheet module

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: hide tab if cell equals "Yes"

    Hi there,

    See if the attached workbook does what you need. It uses the following code in the VBA CodeModule of the "Dashboard" worksheet:

    Please Login or Register  to view this content.
    The highlighted values may be changed to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    09-18-2017
    Location
    San Francisco
    MS-Off Ver
    2013
    Posts
    39

    Re: hide tab if cell equals "Yes"

    Thank you!
    Greg, in your example you have a drop down showing yes or no.
    In my case it's a formula, and it could be anything.
    So if it is yes or no, i need it hide the audit tab, but if for example is says "sales" then leave it visible.

    How can I adjust your code to do that?

    Thanks!

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: hide tab if cell equals "Yes"

    Hi again,

    Just remove the data validation from the cell and replace its contents with your formula. In fact, if you just clear the contents of the cell (instead of selecting "No" from the dropdown), the tab will be hidden.

    Regards,

    Greg M

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: hide tab if cell equals "Yes"

    Change events are not triggered by formulae, What is the formula?

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: hide tab if cell equals "Yes"

    If the only cells that D8 looks at are on the Dashboard sheet, you could use
    Please Login or Register  to view this content.

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: hide tab if cell equals "Yes"


    Change events are not triggered by formulae

    Nice one, Fluff13 - my bad for not noticing the implication of the changed requirement!


    Hi again alisachsf,

    I think the following code should do what you need:

    Please Login or Register  to view this content.

    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M

  9. #9
    Registered User
    Join Date
    09-18-2017
    Location
    San Francisco
    MS-Off Ver
    2013
    Posts
    39

    Re: hide tab if cell equals "Yes"

    Thank you both! Really appreciate the help.

    Unfortunately I get an error on the Me.Range (invalid use of Me keyword).

  10. #10
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: hide tab if cell equals "Yes"

    Hi again,

    That error suggests that you've entered the code in a standard VBA CodeModule - it must be entered in the VBA CodeModule for the worksheet in question.

    Hope this helps,

    Regards,

    Greg M

  11. #11
    Registered User
    Join Date
    09-18-2017
    Location
    San Francisco
    MS-Off Ver
    2013
    Posts
    39

    Re: hide tab if cell equals "Yes"

    So I added it to the Dashboard tab module where I already have a call macro.
    The new macro (to hide a tab) doesn't work automatically, but when I added a line to the call it created an error.
    Right now I have the following under the Dashboard module:

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Last edited by alisachsf; 08-28-2019 at 02:30 PM.

  12. #12
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: hide tab if cell equals "Yes"

    Hi again,

    The "Worksheet_Hide" routine declares "Target" as an argument:

    Please Login or Register  to view this content.
    but you have not passed any argument to it in the calling statement:

    Please Login or Register  to view this content.

    The calling statement should read:

    Please Login or Register  to view this content.

    Hope this helps.

    Regards,

    Greg M

  13. #13
    Registered User
    Join Date
    09-18-2017
    Location
    San Francisco
    MS-Off Ver
    2013
    Posts
    39

    Re: hide tab if cell equals "Yes"

    That didn't work, not sure why. But I switched the code to the following and now it works!
    Please Login or Register  to view this content.
    Thanks for your help!

+ 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. [SOLVED] Macro to show & hide rows based if cell B4 equals to "WEEKLY"
    By ricdamiani in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-10-2018, 08:25 PM
  2. Replies: 1
    Last Post: 06-27-2017, 08:27 PM
  3. [SOLVED] Day counts, formulas between colums. "c" minus "f" = equals ???.
    By israelalvarado in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-28-2017, 05:58 PM
  4. [SOLVED] If cell equals "CR" then make cell to left negative and delete "CR".......
    By pasqualebaldi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-14-2016, 07:51 PM
  5. Replies: 1
    Last Post: 09-21-2013, 03:18 AM
  6. If cell equals "x" move row to sheet "x", If cell equals "y" move row to sheet "y"
    By snappyleon in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-01-2013, 03:19 AM
  7. [SOLVED] Delete row if cell in Column N equal "Different" or Column P equals "Blank"
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2012, 08:25 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