Share via

locking cells after input, or showing if input has changed

Anonymous
2013-01-31T17:17:55+00:00

Hi

Is there a way in which i can lock cells after other users have put in a date,

for example, i have a project start column, another user puts in a start date. What i want to know is there a way that i can imiediatly automatically lock that cell so they cant change the date, or is there another way i can do so. or can i highlight the cell if it has changed from the original date? there are several hundered rows of data.

thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2013-01-31T18:29:54+00:00

    This can be done with an event macro.  Lets assume that we start with the worksheet password-protected with the password "obvious", but all the cells in column A unlocked.

    Enter the following macro in the worksheet code area:

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim A As Range

    Set A = Range("A:A")

    If Intersect(Target, A) Is Nothing Then Exit Sub

    ActiveSheet.Unprotect Password:="obvious"

    Target.Locked = True

    ActiveSheet.Protect Password:="obvious"

    End Sub

    Once a value has been entered in a cell in column A, the macro:

    • un-protects the sheet
    • locks the cell
    • re-protects the sheet

    Because it is worksheet code, it is very easy to install and automatic to use:

    1. right-click the tab name near the bottom of the Excel window
    2. select View Code - this brings up a VBE window
    3. paste the stuff in and close the VBE window

    If you have any concerns, first try it on a trial worksheet.

    If you save the workbook, the macro will be saved with it.

    If you are using a version of Excel later then 2003, you must save

    the file as .xlsm rather than .xlsx

    To remove the macro:

    1. bring up the VBE windows as above
    2. clear the code out
    3. close the VBE window

    To learn more about macros in general, see:

    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    To learn more about Event Macros (worksheet code), see:

    http://www.mvps.org/dmcritchie/excel/event.htm

    Macros must be enabled for this to work!

    3 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-02-06T12:49:42+00:00

    A one line addition:

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim A As Range

    Set A = Union(Range("B:B"), Range("E:F"), Range("Q:Q"))

    If Intersect(Target, A) Is Nothing Then Exit Sub

    If Target.Value = "" Then Exit Sub

    ActiveSheet.Unprotect Password:="obvious"

    Target.Locked = True

    ActiveSheet.Protect Password:="obvious"

    End Sub

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2013-02-06T11:01:18+00:00

    Hi

    This macro works great, however, when i click on the cell within a range specified in the macro, and then click off of it, the macro still locks the cell even though there is no values put into there, so is there a way which i can leave blank cells unlocked but cells that have an actual values in them locked after the value is inputed.

    For example, in column A i have used the above macro and it has achieved what i want, but if i doule click a cell then click off it, without putting anything in the cell, that cell becomes locked, i dont want this so is there a code which will unlock the cell if it is blank, but when the cell as values in it, e.g. x345, it is then locked.

    0 comments No comments
  4. Anonymous
    2013-02-04T14:04:56+00:00

    A single line replacement:

    Just replace the Set command with:

    Set A = Union(Range("B:B"), Range("E:F"), Range("Q:Q"))

    0 comments No comments
  5. Anonymous
    2013-02-04T13:24:16+00:00

    thanks,

    How would i make it so that several columns perform the same way,

    e.g. columns b,e,f,q

    0 comments No comments