+ Reply to Thread
Results 1 to 6 of 6

Automatically update a protected cell based on contents of an unprotected cell

  1. #1
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Automatically update a protected cell based on contents of an unprotected cell

    Hello.

    I am trying to find some VBA that will allow protected cells to be updated when a user enters or selects data in other cells.

    For example:

    Cell 'A1' starts out blank.
    Cell 'B1' has a drop down to select specific items.
    Cell 'C1' is the date of the order and is a locked cell.
    Cell 'D1' is the date of completion and is a locked cell.
    The worksheet is protected to prevent direct changes to cells C1 and D1.

    If a user enters any information in A1, then C1 displays the current date.
    If a user selects 'Complete' from the drop-down list in B1, then D1 displays the current date. Both of these actions are independant of one another.

    This format is the same for every cell in the 4 columns indicated above. I thought I was able to do this in another spreadsheet I created a year or so ago but I have not been able to figure out what I did and I do not have the spreadsheet to look at. Any help would be appreciated.

    Thanks,
    Andrew
    Last edited by drewship; 05-01-2009 at 12:30 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Automatically update a protected cell based on contents of an unprotected cell

    These are worksheet_change events. Right-click on the sheet tab and select VIEW CODE, then paste in this code...edit to your needs:
    Please Login or Register  to view this content.
    This will do what you want, make sure columns A and B are unlocked prior to locking the sheet.

    If there is ALREADY data in columns C and D when you make another change to the adjacent A & B cells, the macro will give you the option to LEAVE the date that is in there already.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Automatically update a protected cell based on contents of an unprotected cell

    Thanks JBeaucaire!! This works...but you already knew that. The only thing that I need to check with the users is if they get a popup asking for the password to unlock the sheet. It did the first time I ran it, but after saving, closing and reopening it, the popup did not return. I don't want them to have the password so hopefully it was just a fluke. I will close this thread after some additional testing.

    Andrew

  4. #4
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Automatically update a protected cell based on contents of an unprotected cell

    Update: I am including my spreadsheet and hopefully someone can help with a couple issues that have come up.

    The first is that I emailed this to a couple of users and the code to autopopulate the dates does not work for them. One has Excel 2003 SP2 and the other has Excel 2003 SP3. I wrote this with Excel 2003 SP3 and on my machine, I do not have any issues. I wrote it on the Excel 2003 SP2 machine and it worked until I saved it and closed Excel. When I opened the file on the same SP2 machine, the dates do not autopopulate.

    The second issue is I need to check if any of you get a popup asking for the password to unprotect the sheet. Ideally the protected cells need to be updated without the user needing to ented the password since that defeats the purpose. The password is

    test

    Additionally, I need to place the product of cells F and J (this will be based on the item selected in cell E from a drop down box), in cell K (which will be locked) I looked through a bunch of posts but did not see any code that might work in my case.

    Thanks in advance,
    Andrew
    Attached Files Attached Files

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Automatically update a protected cell based on contents of an unprotected cell

    First issue - different people set up their local machines differently. They may have theirs set to NOT run macros and NOT ask, just don't run them. This stuff only works with macros enabled.

    Second issue - The "UserInterfaceOnly" flag is not a setting that is retained when the sheet is closed. It has to be reset.

    Change the macro I gave you to include the password, which I didn't really think was necessary. Obviously you need to put in the correct password.
    Please Login or Register  to view this content.
    Another option would be to set the flag in a WorkBook_Open macro so it's taken care of immediately. Up to you. Of course, since I don't know your password, I can't make further edits on this sheet.

    Last Issue - there's no need to do in macro what a worksheet function will. Put a formula in K3 and copy down:

    =J3*F3


    Then go to TOOLS > OPTIONS > VIEW > [ ] Zero Values and uncheck that flag so this sheet doesn't show the zeros for incomplete rows (optional)

  6. #6
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Automatically update a protected cell based on contents of an unprotected cell

    Thanks!! The password is 'test' without the quotes...I thought I included it in my post. I will just add the password to the code since they don't know how to mess with it.

    I will check the other workstations to ensure macros are enabled...I assume they are because the users don't know how to mess with those things.

    I did have the formula =J3*F3 but took it out so I could try some code but it is just as easy this way.

    Andrew

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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