OK here's a worksheet change macro you can use.
First, on your worksheet unlock all the cells in columns A & B (select both columns then Home>Cells>Format and click on Lock Cell. Be sure you have allowed users to select both locked and unlocked cells when you have protected the sheet.
To install the code:
1. Right-click the worksheet tab you want to apply it to and choose 'View Code'. This will open the VBE window.
2. Copy the code below from your browser window and paste it into the white space in the VBE window.
3. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
4. Make sure you have enabled macros whenever you open the file or the code will not run.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lR As Long, c As Range
lR = Range("A" & Rows.Count).End(xlUp).Row
If Not Intersect(Target, Range("B1:B" & lR)) Is Nothing Then
Me.Protect Password:="", userinterfaceonly:=True 'Add your password between the " marks
For Each c In Range("A2:A" & lR)
If c.Value = c.Offset(-1, 1).Value Then
c.Locked = True
Else
c.Locked = False
End If
Next c
End If
End Sub
After you have installed the code, you can start it by entering a value in any B cell (if there is already a value there just enter that same value again). That's it, your A cells that equal the value in the B cell one row above will all be locked automatically. Or unlocked after being locked if the B companion should be changed so the value in A is no longer equal to its B companion.
Be sure to put your password into the code where indicated by the comment.