+ Reply to Thread
Results 1 to 16 of 16

'Unlock' Code is Unprotecting Sheet

  1. #1
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    'Unlock' Code is Unprotecting Sheet

    Hi,

    On my AFRsInput sheet there are 2 yellow shapes upper left. One for 'Lock' which locks the cells D5:D19 and L4:L7 and fills them with gray. This works like it should.

    The other yellow shape 'Unlock' asks for password ('clerk') to unlock those cells which it does. But it also unprotects the sheet which is bad.

    Can someone please make it so the sheet remains protected ?

    Thank you,
    Fred

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: 'Unlock' Code is Unprotecting Sheet

    Can you post the code that runs off the yellow shape? This is going to be a quick one and.....at 4.30pm after a long day of listening to the fella at the desk next to mine sniff, cough and sneeze his way through today I really can't be bothered to download your attachment.

  3. #3
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    Yes sorry:

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: 'Unlock' Code is Unprotecting Sheet

    gonna need 'FormUnlock' and 'FormLock' as well pls.

  5. #5
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    Maybe all of this:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: 'Unlock' Code is Unprotecting Sheet

    Just in case I decide to give up for the day and go home, what's happening is your code is successfully editing the cells but not protecting the sheet once it's finished. Either, the method you're using to detect if the sheet should be protected or not is returning an incorrect value and your code to lock it all again isn't triggering.....or your code to protect the sheet is having an error.

  7. #7
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: 'Unlock' Code is Unprotecting Sheet

    Please Login or Register  to view this content.
    looks fine to me. Which suggests the code to protect the sheet once your macro has finished unlocking cells isn't triggering. What's interesting is the switch 'useinterrfaceonly=true' should remove the need to unlock the sheet before making changes.

  8. #8
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    I'm not sure sorry this is why I ask for help. Thanks if you have to leave.

  9. #9
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: 'Unlock' Code is Unprotecting Sheet

    Step through your code (click in the margin on the first line to set a break point - press F8 to step though line by line). What value is the 'shtprotected = Sheet1.ProtectContents' returning?

    If it's returning anything but 'True' then we've found the problem.

  10. #10
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    it keeps cycling through the top part of the ClerkUnlock code

  11. #11
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: 'Unlock' Code is Unprotecting Sheet

    Ok, just admitted defeat and downloaded your attachment. The shtprotected part is definitely returning 'False' as the value, so your protect code will never trigger. That's the problem. You'll need to come up with another method of deciding whether or not a sheet needs to be protected.

    However, as I mentioned earlier, the 'UserInterfaceOnly' switch you're using when you protect a sheet negates the need to unprotect that sheet again, VBA code will still be allowed to make changes despite the sheet being protected. The only caveat to using it is that Excel 'forgets' the switch every time you close the workbook, so when you load it again tomorrow none of your protected sheets will have the userinterfaceonly switch set.....until you unprotect them and re-protect them again with the switch.

    The usual method I use to get around this is in the workbook_open event I put code to unprotect and reprotect every sheet.....when the workbook opens (clue's in the name of the event). Once you've got userinterfaceonly setup consistently there'll no longer be any need to unprotect a sheet when you want to unlock specific cells.

  12. #12
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: 'Unlock' Code is Unprotecting Sheet

    And on that note I'm giving up for the day. Good luck and if you're still having trouble tomorrow I'll jump in and re-write what you've got there.

  13. #13
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    I appreciate the extensive help you are providing but it is a bit advanced for my knowledge thus far.

  14. #14
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    Thanks BellyGas I will keep trying. Enjoy your evening.

  15. #15
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    I came up with a possible solution:

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    03-12-2019
    Location
    USA
    MS-Off Ver
    2010
    Posts
    421

    Re: 'Unlock' Code is Unprotecting Sheet

    Not sure what the FormLock and FormUnlock do but I made them comments and the sheet remains protected during the Lock and Unlock.

+ 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] How to stop Sheet change event affecting all other cells by unprotecting the sheet
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-16-2018, 12:59 PM
  2. VBA Code to unlock cells on a protected sheet based on cell value in another worksheet
    By mr_irrelevant in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-13-2014, 04:02 PM
  3. Unprotecting sheet
    By familylink in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2011, 02:35 AM
  4. [SOLVED] Unprotecting a Sheet
    By SergioCorreiaMaputo in forum Excel General
    Replies: 3
    Last Post: 06-20-2006, 06:00 AM
  5. [SOLVED] Password Protecting/Unprotecting Via Code
    By MWS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2005, 11:25 AM
  6. Unprotecting VBE Project to Make Code Changes
    By Kaisies in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2005, 05:06 PM
  7. Unprotecting sheet
    By PeterG in forum Excel General
    Replies: 0
    Last Post: 01-20-2005, 12:24 PM

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