+ Reply to Thread
Results 1 to 10 of 10

Can you lock a cell or prevent it from being edited with a formula?

  1. #1
    Registered User
    Join Date
    06-29-2008
    Location
    Tyler, TX
    Posts
    39

    Question Can you lock a cell or prevent it from being edited with a formula?

    Greetings again-


    I've run into a situation that was submitted to me, by my boss. I'm creating a Concrete Mix Design, and there are certain ACI & ASTM Standards we have to go by to calculate how much cement, water, & fly ash have to be added to the aggregate.

    We also have to include "adjustment" cells, so that if the contractor decides he wants to add more cement than the "Standard", we will be able to adjust it w/o re-writing the formula. Well, if he makes an adjustment, then it no longer meets the "Standards".

    On my Data Sheet, I will have a drop-down box that asks if the design meets "ACI Standards". If 'YES' is chosen, then a title under the heading will appear and say: "THIS MIX DESIGN MEETS ACI STANDARDS" And, of course, if 'NO' is chosen, then the title will not show up.

    OK, so here is my question:

    If 'YES' is selected, I would like to lock the adjustment cells, so that you don't accidentally say it meets standards, and then still be able to put a value in the adjustment cell.....which would throw it out of standards.

    Is that even possible? Just in case it isn't, is there a formula to change the text color in a cell, or change the fill color in a cell, or finally a formula to automatically change a value to "0" if 'YES' is selected and leave the value alone if 'NO' is selected?


    Have I thoroughly confused you yet? Sorry, for the long ramble, and all the run-on sentences.


    Any help is appreciated. Thank you in advance.


    -Bryan

  2. #2
    Forum Contributor stephenloky's Avatar
    Join Date
    07-10-2013
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    Excel 2007
    Posts
    146

    Re: Can you lock a cell or prevent it from being edited with a formula?

    You need a macro to do that.
    "The quieter you become, the more you are able to hear"

    Any reputation (*) points appreciated.

    "If you know yourself but not the enemy, for every victory gained, you will suffer defeat."

  3. #3
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Can you lock a cell or prevent it from being edited with a formula?

    Another way to go, is to just alter how the formulas use those adjustment cells.



    Here's the basic idea. Where ever you have the formula, you would need to do this:

    =CHOOSE((SelectionCell="yes")*1+1, normal_Formula_here, formula_ignoring_adjustment_cells_here)

    So, you would need one version of the formula that makes use of the adjustment cells and another version that ignores them. You would then "choose" which to use based on whether or not they say "yes" or "no" in the other cell.


    If this is not clear, please post an example for more help
    Last edited by GeneralDisarray; 07-10-2014 at 02:22 PM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    06-29-2008
    Location
    Tyler, TX
    Posts
    39

    Re: Can you lock a cell or prevent it from being edited with a formula?

    I have attached a file, to better help with understanding my issue. If you have any questions, please ask.


    -Bryan
    Attached Files Attached Files

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Can you lock a cell or prevent it from being edited with a formula?

    Just replace the formulas.

    In cell C12: =CHOOSE(1*(D5="YES")+1,((((+C8*94)+C13))-((((C8*94)+C13)*C18)/1.2)),((((+C8*94)))-((((C8*94))*C18)/1.2)))

    In cell C16:=CHOOSE((D5="YES")*1+1,((+C8*94)*C18)+C17,((+C8*94)*C18))


    What this will do, is provide two formulas to use for the calculations. The "YES" version of the formula will just ignore the adjustment values.
    Last edited by GeneralDisarray; 07-10-2014 at 04:36 PM.

  6. #6
    Registered User
    Join Date
    06-29-2008
    Location
    Tyler, TX
    Posts
    39

    Re: Can you lock a cell or prevent it from being edited with a formula?

    Thank you for the help, but I can't quite do it like that. All of that data is referenced on a MIX DESIGN REPORT, so even if the calculation ignores some of the values, they will still appear on the report.

    I think I'm gonna try to learn some kind of complicated IF/THEN (AND) statement. Instead of where I had the YES/NO menu in D5, I'm gonna try to say something like this: "IF the SAND ADJUSTMENT cell =0, AND the CEMENT ADJUSTMENT cell =0, AND the FLY ASH ADJUSTMENT cell =0, AND the WATER ADJUSTMENT cell =0, AND the WATER/CEMENT RATIO cell does not say "CUSTOM", THEN say "YES" in D5, otherwise say "NO".

    Can you help me with a bunch of IFs, THENs, & ANDs??

  7. #7
    Valued Forum Contributor
    Join Date
    04-22-2014
    Location
    Auckland, New Zealand
    MS-Off Ver
    Office 365 (work) and Excel 2013 (home)
    Posts
    1,167

    Re: Can you lock a cell or prevent it from being edited with a formula?

    Try this in D5:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    1 IF statement and 1 AND statement with multiple conditions.
    Please add reputation by clicking on the * if I have helped.
    Please mark the thread SOLVED if your issue has been resolved.
    Thanks, Glenn.

  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Can you lock a cell or prevent it from being edited with a formula?

    If you want those numbers to not appear in a report, then you can control the formatting of the cells containing the numbers.

    You can make the Font color (for the adjustment cells) match the background color - so they will appear blank - when "YES" is selected. That will keep them from appearing on the report.

    So to sum up, the solution i would suggest is: use CHOOSE() to keep those cells out of the formulas and conditional formatting to keep them from appearing in the report - that would allow you to complete this without macros.

    ----

    See attachment for your preferred solution.

    With macros you can use the protected area idea you started with, but you need to alter your understanding just a bit. You will have to define all the areas the user can edit and not the areas you want to protects i.e., you don't identify what NOT to protect and everything else is off limits.

    To make the unlocked area change with the selection of "YES" or "NO" you will need to use a worksheet_change() event like this:


    This solution requires named ranges to identify the unlocked areas, and a worksheet_change event macro to control what is locked depending on a selection cell (which is also a named range ACI_Choice).




    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-29-2008
    Location
    Tyler, TX
    Posts
    39

    Re: Can you lock a cell or prevent it from being edited with a formula?

    Thank you for everyone's help. gak67's IF statement will work best. Rather than locking cells, I will allow changes to be made in the adjustment cells, which will make D5 say no....and the heading that will say, "THIS DESIGN MEETS ACI STANDARDS" will not appear. If conditions are correct, then it will appear.

    I did learn something new with GeneralDisarray's formulas, so that is a bonus. Thanks!!


    -Bryan

  10. #10
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Can you lock a cell or prevent it from being edited with a formula?

    No problem. Please mark your thread "[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. Lock cell from being edited or copied/pasted
    By da_sprite in forum Excel General
    Replies: 1
    Last Post: 09-09-2012, 01:10 AM
  2. Replies: 0
    Last Post: 07-19-2012, 07:31 AM
  3. Prevent multiple cells selection & Lock Cell
    By jieyi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2008, 06:09 AM
  4. pROTECT OR lOCK CELLS SO THAT THEY CANNOT BE EDITED
    By facmess1 in forum Excel General
    Replies: 1
    Last Post: 05-31-2007, 05:26 PM
  5. [SOLVED] Lock Cells to Prevent Changes
    By In Calif in forum Excel General
    Replies: 4
    Last Post: 09-14-2005, 01:05 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