+ Reply to Thread
Results 1 to 7 of 7

Is it possible to detect when a user clicks on a locked cell in a protected sheet?

  1. #1
    Registered User
    Join Date
    07-17-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2013
    Posts
    8

    Is it possible to detect when a user clicks on a locked cell in a protected sheet?

    We use a macro-enabled workbook for our field personnel to fill out reports digitally where:

    • cells for data entry are not locked
    • sheet protection is set to "Select unlocked cells only"

    Thus, the guys can get into and edit only the unlocked cells. I have code that runs whenever certain cells are right-clicked (places a checkmark, inserts "Pass" or "Fail", etc).

    Here's the problem:
    If the user right-clicks on one of these unlocked cells (ie: to place a checkmark) then clicks elsewhere in a locked cell (perhaps by accident, adjacent to another unlocked cell on the other side of the form), the target is still at the first cell. This means the code executes the right click event on the target, which is still on the other side of the form. This is tricky, because he's not looking at that last cell he clicked on when it changes his checkmark to an "X" (or whatever my code is set to do on that type of cell). This has the potential of changing something that was "Acceptable" to "Rejectable" or vice versa. Can't have that!

    Is it possible to detect when the user attempts to right click on a locked cell in a protected sheet? If a message box can be made to pop up and say "You're not allowed in this cell, sorry bud!", then I can restrict my BeforeRightClick macro to only run if the cell he's trying to right-click on is unlocked.

    Again, this sheet is protected for selection of unlocked cells only, so checking the target range isn't an option.

    Thanks!

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Is it possible to detect when a user clicks on a locked cell in a protected sheet?

    The event is not happening for the locked cell, as they can not select locked cells, but rather for the cell that is active.

    You could check whether the active cell changed since last right click and ask user to confirm action

    to test unlock a few cells and protect worksheet. Add code to worksheet object
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Is it possible to detect when a user clicks on a locked cell in a protected sheet?

    Putting this ahead of the rest of your rightclick event in the workbook should also stop it from running your part of code if the sheet is protected and cell locked.
    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Registered User
    Join Date
    07-17-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Is it possible to detect when a user clicks on a locked cell in a protected sheet?

    Thanks Andy.

    That got me about 50% of the way there, but if I right-click an unlocked cell two times in a row, it will throw the notification like it's locked.

    RightClick_OutofBounds_Test.xlsm

  5. #5
    Registered User
    Join Date
    07-17-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Is it possible to detect when a user clicks on a locked cell in a protected sheet?

    Arkadi, I tried that but won't Target.Locked always be false, since you can't technically be targeting a locked cell on a protected sheet?

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Is it possible to detect when a user clicks on a locked cell in a protected sheet?

    That is the best you can do, unless you let them select locked cells.

    The message is to inform them that they are still affecting the same cell. The reason I used a yes/no msgbox is that it might be the user does want to re-edit the cell.

  7. #7
    Registered User
    Join Date
    07-17-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Is it possible to detect when a user clicks on a locked cell in a protected sheet?

    Ah, thank you Andy. I tried and tried this afternoon but you are absolutely right.

    I was hoping to get somewhere by comparing the current and previously clicked cell. If the user right-clicked in the same box, but co-ordinates of that cell did not change during the click event, then it would allow the code to run. But alas, it's too complicated for me.

    For the record, this is as far as I got: RightClick_OutofBounds_Test (Take 2).xlsm

+ 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. Replies: 8
    Last Post: 03-16-2015, 08:31 AM
  2. Prevent user from moving cell in locked sheet?
    By brandonlaw in forum Excel General
    Replies: 1
    Last Post: 08-08-2012, 08:23 AM
  3. Formatting cell within a Protected and Locked Sheet
    By drgogo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2009, 12:53 PM
  4. How to allow user paste(Ctrl + V) a row to protected sheet(some columns are locked)
    By openSuSe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2008, 07:35 AM
  5. Replies: 0
    Last Post: 06-20-2006, 02:50 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