+ Reply to Thread
Results 1 to 3 of 3

Thread: IF function true, protect cell?

  1. #1
    Registered User
    Join Date
    12-23-2010
    Location
    Honolulu, HI
    MS-Off Ver
    Excel 2003
    Posts
    4

    IF function true, protect cell?

    I am creating a database for others to enter data. Is it possible to use conditional formatting to "lock" or protect certain cells? For example, if someone types "0" into A1, is it possible to lock cells B1 through E1, effectively requiring them to be skipped?

    Not sure if this will become an issue, but all the cells have data validation as well, although blanks can be ignored.

    If this is possible, I will be needing pretty detailed instructions (i.e. exact formula to type into cell, or menu option play-by-play... I am semi-new to all of this

    Thanks!

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004

    Re: IF function true, protect cell?

    Hit ALT F11
    Select the sheet that you are working on (Sheet1 for instance).
    Paste in the following code.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Address = "$A$1" Then
        Me.Unprotect
        If Target = 0 Then
            Range("$B$1:$E$1").Locked = True
        Else
            Range("$B$1:$E$1").Locked = False
        End If
    End If
    
    'Repeat above segment as necessary for other cells
    
    
    Me.Protect
    End Sub
    Hit ALT F11 again to get back to the worksheet.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  3. #3
    Registered User
    Join Date
    12-23-2010
    Location
    Honolulu, HI
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: IF function true, protect cell?

    Thanks, mrice. I think this will work, but I'm on my home computer, which is a Mac. Can you use this type of code on Excel for Mac (2008)? ...not sure if this is considered a "macro," but I don't think macros can be used on excel for Mac. I'll try on Monday when I go back to work.

    In the mean time, is there any type of shortcut where I could make sure that the code works for every row (I have allowed for up to 100 rows of data, so I don't want to have to repeat the code 100 times so that it works for each record).

    Thanks so much for your help!

+ 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.2.0