+ Reply to Thread
Results 1 to 7 of 7

Locking edited cells

  1. #1
    Registered User
    Join Date
    08-12-2009
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2007
    Posts
    53

    Locking edited cells

    I hope someone can help, my VBA is some what limited, its been a long time.
    The code I have put together is working ok apart from a few small problems.
    Im hoping someone can look at my code and tell me where i'm going wrong.

    If I explain what it is ment to do first, then this should make things easier.
    Basically, when a user inputs any text in to a cell the cell automatically creates a comment of when, what and who by, and then locks the cell preventing further editing. This all works fine. So whats the problem? Users have started using copy and paste when multiple entries are required. If a single protected cell is copied to another single cell then the code still works fine, but if a single cell is copied and pasted into multiple cells then the value is copied to the cells, but the multiple cells do not lock? If the value in these cells is edited further then they lock.
    So basically I need the code to work when multiple cells have been pasted, rather than just one cell being edited.

    Hope someone is able to help?

    Here is the code:-
    Please Login or Register  to view this content.
    Last edited by royUK; 08-12-2009 at 08:20 AM. Reason: add code tags

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    re: Locking edited cells

    Please take the time to actually read the Forum Rules that you agreed to when joining. Your post title & lack of Code Tags break the forum Rules. I will edit this once onlY!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-12-2009
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Locking edited cells

    Cheers, sorry about that!

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Locking edited cells

    Well, for starters, the following code line checks to see if there are more than 1 cell in the area being changed, and if there are then it exits the routine altogether, so that is why it does nothing when there are multiple cells being changed.
    So you need to move that line, and then code the rest of the function to deal with multiple values, (that is, Target containing a range of more than just one cell).

    However I have tried a couple of variations around this and all I get is questions

    - After a cell is edited your code locks the cell and protects the sheet;
    -- Presumably when originally setting the sheet up you have UNLOCKED all the cells on the sheet? Otherwise as soon as you protect it no-one can do anything more anyway.
    -- Once you have locked a cell, it can't be changed without unlocking the sheet, so how would the 'comment' ever build up a history?
    -- Do your users have the 'Unprotect' password, and if so what is the point in protecting the worksheet in the first place?

    - Finally, assuming your users have the 'Unprotect' password so that they can edit the sheet, if you allow them to copy & paste (even a single cell to a single cell), the COMMENT is also included in the copy, so it destroys the history of that cell.

    I don't believe you can stop them BEFORE they paste the data in, thus destroying your data and history, so perhaps you should be stopping them from being able to paste at all?
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  5. #5
    Registered User
    Join Date
    08-12-2009
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2007
    Posts
    53

    Talking Re: Locking edited cells

    Hey Phil, thanks for the reply.

    Yes, when originally setting the sheet, all cells that needed to be unlocked were unlocked. So users can only edit cells they need to.
    The comment history is only really for an audit trail of any changes (mistakes) that have been needed to be made by a supervisor (system administrator). So only the supervisor needs the unprotect password to make any changes to locked cells.
    The code is for a stock control workbook, so the user will only be using paste when entering multiple items of stock on the same day, which means its ok that the initial comment is copied as the information in the comment would still be correct, as the user can copy locked cells but not paste over locked cells, only paste into empty cells.

    I have removed this line of code.
    Please Login or Register  to view this content.
    But would you be able to help with coding the rest of the function to deal with multiple values? Im not really sure where to start?

  6. #6
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Locking edited cells

    Please try the following code and see if it suits your purpose.
    There are a couple of things that might trip up the 'comments' section, but from the way it is being used I don't think you will encounter them.

    Of course if you have any questions please do ask

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-12-2009
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2007
    Posts
    53

    Thumbs up Re: Locking edited cells

    Hey,

    That’s works great, was working on something similar, but was still trying to use Undo, and couldn’t figure out why it wasn’t working! Using previous value from comment works even better, actually runs smoother, THANKS.

    You mention that a couple of thing could trip up the 'comments' section, what would they be? Just so I am aware of them.
    Also, could you explain the 'On Error' lines of code?

    Thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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