Lock Cells After Entry

pwielgosh

New Member
Joined
Aug 8, 2014
Messages
22
Hi,

I've browsed the forums and tried searching Google but am unable to come up with the information that I need. I know very little VBA and would like to lock certain cells within a worksheet. My worksheet name is Receipt List. Data will potentially be entered in A4 through AO5000. I would like a vba code that once information is entered in column J it will lock all the cells in that row in columns A through J and do this for each row.

Once this worksheet is implemented data will start to be entered in A4 and will continually go down. So every time information is entered in column J I want everything in that row and above to remain locked unless a password is used. Another user will be entering information in columns K through AO so I do not want to have to enter a password each time and these cells do not contain information that need to be locked.

Any help on this would be greatly appreciated!

Thank you!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Locked cells only work if both:
- the cells are locked
- the sheet is protected

By default, all cells on an Excel file are locked, but the sheet is not protected. So the first thing you have to do is unlock all the cells you want to be able to enter data into initially (this may be whole sheet, or just certain sections of it). So:
1. Select the range you wish them to be able to type information into.
2. Right click and select Format Cells
3. Go to the Protection tab
4. Uncheck the Locked Box

Now, password Protect your Sheet.
1. Go to the Review tab
2. Click Protect Sheet
3. Make sure the first two items are checked
4. Enter a password (and remember it!)
5. Click OK.

Now, we want to use Event Procedure VBA code that will fire whenever a cell in column J is updated. So do the following:
1. Right click on the Worksheet tab name at the bottom of your screen
2. Select "View Code"
3. Enter the code below into the VB Editor window
4. Change the two references to "password" to the password that you have chosen
5. Save the code

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Check to see if entry made in column J
    If Target.Count = 1 And Target.Column = 10 And Target.Row >= 4 And Len(Target) > 0 Then
        ActiveSheet.Unprotect Password:="password"
        Range(Cells(Target.Row, "A"), Cells(Target.Row, "J")).Locked = True
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="password"
    End If

End Sub
This should now do what you want.
 
Upvote 0
Glad I could help!:)
 
Upvote 0

Forum statistics

Threads
1,215,018
Messages
6,122,703
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top