+ Reply to Thread
Results 1 to 9 of 9

hide/unhide worksheets (Advanced VBA Code)

  1. #1
    Registered User
    Join Date
    08-26-2023
    Location
    united states
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2304 Build 16.0.16327.20200) 32-bit
    Posts
    3

    hide/unhide worksheets (Advanced VBA Code)

    Hello Everyone,
    I'M looking for help to create VBA code that will require a password to toggle a cell
    example:
    sheet 1 cell Q1 is a drop down box with Open or Closed to toggle this function I would like to use a password in this cell to be able to select an option.
    If sheet 1 = open, password required to unhide sheet 2
    if sheet 1 = closed , no password required to hide sheet 2

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,836

    Re: hide/unhide worksheets (Advanced VBA Code)

    Welcome to the forum.

    Which version of Excel do you have? Please update your forum profile.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    08-26-2023
    Location
    united states
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2304 Build 16.0.16327.20200) 32-bit
    Posts
    3

    Re: hide/unhide worksheets (Advanced VBA Code)

    **UPDATED** And I'm using version Microsoft® Excel® for Microsoft 365 MSO (Version 2304 Build 16.0.16327.20200) 32-bit

  4. #4
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: hide/unhide worksheets (Advanced VBA Code)

    Quote Originally Posted by t.folsom80 View Post
    Hello Everyone,
    I'M looking for help to create VBA code that will require a password to toggle a cell
    example:
    sheet 1 cell Q1 is a drop down box with Open or Closed to toggle this function I would like to use a password in this cell to be able to select an option.
    If sheet 1 = open, password required to unhide sheet 2
    if sheet 1 = closed , no password required to hide sheet 2
    To be clear ... you want:
    1. the user to enter a password in sheet1 cell Q1 in order to be able to change the value in that same cell, and
    2. if the user subsequently sets the value to open then no password is required to activate sheet 2 but if it is set to closed then password required.

    Is that right?
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  5. #5
    Registered User
    Join Date
    08-26-2023
    Location
    united states
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2304 Build 16.0.16327.20200) 32-bit
    Posts
    3

    Re: hide/unhide worksheets (Advanced VBA Code)

    Hello, That is correct

    And Thank you for the response!!

  6. #6
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: hide/unhide worksheets (Advanced VBA Code)

    There are two issues with what you're trying to do:

    1. Entering a password that is not in the list of acceptable values is problematic. You wouldn't ask for the password to change the selection until after the user had attempted to do so, which means entering a password in the same cell. This can be overcome but I would suggest using an input box to request the password; if it's correct the value stays as it is and if it's wrong it can be reverted to the previous value.

    2. Excel doesn't have a BeforeActivate or BeforeDeactivate event for worksheets. This means if you use the Activate event of Sheet2 as the trigger to check the sheet access password has been set, there will be a split second where the user can see what is in Sheet2 before being switched back to Sheet1 if it is incorrect. It would be smoother and more secure if Sheet2 was simply hidden from users until the password for sheet access was set.

    What do you think?

    Also, in case you're not aware, this sort of security functionality will keep normal users out but a determined user trying to get around the security can do so if they have a little technical ability.
    Last edited by MatrixMan; 08-27-2023 at 02:09 PM.

  7. #7
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: hide/unhide worksheets (Advanced VBA Code)

    Thinking about this some more, I don't think you need a sheet password. If the user sets Q1 to Open then Sheet2 is visible and they can select it; if Q1 is Closed then Sheet2 is hidden and they can't. As mentioned, if you use the Activate event to test whether a password is required or not, the user will momentarily see Sheet2.

  8. #8
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: hide/unhide worksheets (Advanced VBA Code)

    Something like this - put this in the worksheet module for Sheet1:
    Please Login or Register  to view this content.
    Put this in the workbook module:
    Please Login or Register  to view this content.
    And put this in a normal module:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by MatrixMan; 08-27-2023 at 02:09 PM. Reason: Attached file

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: hide/unhide worksheets (Advanced VBA Code)

    Hopefully I am understanding what you want.
    If the user selects Open from the Q1 drop down they will be asked for a password, if it matches then sheet2 will be visible.
    If they choose Close they won't be asked for a password and sheet2 will not be visible.

    Please Login or Register  to view this content.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

+ 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] VAB/Macro to unhide, unprotect, copy to other worksheets, protect & hide worksheets again
    By Roma1r in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-08-2018, 08:26 AM
  2. Replies: 1
    Last Post: 04-25-2017, 11:23 AM
  3. VBA code to hide/unhide worksheets
    By holli in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2015, 11:34 AM
  4. Hide Unhide Worksheets VBA
    By Playemgraeme in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2014, 04:31 PM
  5. [SOLVED] PW Protected Macros Needed to 1) Hide Certain Worksheets & 2) Unhide Worksheets & Columns
    By Aimee S. in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-21-2014, 10:49 AM
  6. Help with VBA Code (Hide/Unhide Worksheets)
    By maryren in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 12:43 PM
  7. Excel 2007 advanced macros assigned to button to Hide/Unhide Rows
    By newbie77 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-08-2011, 01:05 PM

Tags for this Thread

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