+ Reply to Thread
Results 1 to 11 of 11

Conditionally Locking Cells

  1. #1
    Registered User
    Join Date
    08-20-2007
    Posts
    41

    Conditionally Locking Cells

    Hi, I need to lock a cell (F21) if J26 is less than 100. Can't work out how in conditional formatting. Is there a different way?

    This is what I need to do:

    F21=(IF,J26<100,Locked,Unlocked)
    Last edited by beesus311; 02-23-2008 at 08:32 AM.

  2. #2
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Copy the code below to the VBA object of the worksheet these cells are in :

    Private Sub Worksheet_Change(ByVal Target As Range)

    Please Login or Register  to view this content.
    Erik
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  3. #3
    Registered User
    Join Date
    08-20-2007
    Posts
    41

    Question Not sure what that means - please explain further

    I'm not that familiar with how to do that. Could you tell me how that works? Sounds more advanced than I have so far learned.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You could put a custom Validation on F21 of =(99<J26)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    08-20-2007
    Posts
    41
    and how would I do that? I'm not sure what you mean.

  6. #6
    Registered User
    Join Date
    08-20-2007
    Posts
    41
    I've tried that and it doesn't appear to allow me to lock and unlock cells.

  7. #7
    Registered User
    Join Date
    08-20-2007
    Posts
    41

    Question

    What does this mean?

    Private Sub Worksheet_Change(ByVal Target As Range)

    I've entered the VB code - But it doesn't seem to be working.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    For pre-2007:

    Select Cell F21
    Go to the Data Menu and choose Validation
    Perhaps uncheck the Ignore Blanks
    On the Setting tab, choose Custom from the Allow dropdown.
    In the Formula box, type "=(99<J26)" (no quotes).
    If you want the user warned, rather than forbidden, the Error Message tab has that option.
    Click OK

    People will be unable to enter anything in F21 unless 99 < J26.

    It acts a little different than Locking a cell and Protecting a sheet, but prevents inadvertant data entry

  9. #9
    Registered User
    Join Date
    08-20-2007
    Posts
    41
    I need to stop them selecting the cell at all. I'm on 2007.

  10. #10
    Registered User
    Join Date
    08-20-2007
    Posts
    41

    Question

    OK. I'v got that working, but would to prefer to be able to have the cell locked. Do you understand the VB way as outlined by WintE?

    Could you explain exactly how I would go about making that work?

  11. #11
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Hi,

    Unfortunately I made a mistake in the code, Range("K26") should be ("J26") and '> 100' should be '> 99'.

    The way the code works is as follows :

    - In the cell-preferences you sign the protection of cell J26 and F21 unblocked
    - Protect the worksheet.

    Now you're only able to enter data in cell J26 and F21.

    Once you enter a value > 99 cell F21 will be protected.

    Erik

+ 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