Locing collums

Medinukas

New Member
Joined
Apr 18, 2018
Messages
11
Hello I desperetly need help work work.
I need to lock a column if another column has data entered and vise versa
Example I have a column A and B if enter any data in column A then I can't enter any data in column B and vise versa Plz help someone?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Start by unlocking all the cells in columns A and B and then protect the worksheet. Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter data in column A or B.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A:A,B:B")) Is Nothing Then Exit Sub
    ActiveSheet.Unprotect
    Select Case Target.Column
        Case Is = 1
            Target.Offset(0, 1).Locked = True
        Case Is = 2
            Target.Offset(0, -1).Locked = True
    End Select
    ActiveSheet.Protect
End Sub
If you used a password to protect the sheet, then the password will have to be added to the code.

Code:
ActiveSheet.Unprotect Password:="MyPassword"
ActiveSheet.Protect Password:="MyPassword"
 
Upvote 0
How Do i unlock the cell I haven't looked them at all and how exactly do I protect the worksheet. Sorry for these questions i am kida a noob at this
 
Upvote 0
The macro works in the following manner:
Once you unlock columns A and B and protect the sheet, you will still be able to enter data in both columns. However, once you enter data in column A, the corresponding cell in column B will be locked and you will not be allowed to enter data in that cell unless you unprotect the sheet. The reverse is true. Once you enter data in column B, the corresponding cell in column A will be locked and you will not be allowed to enter data in that cell unless you unprotect the sheet. Does that make sense?
 
Upvote 0
Also if I enter the data ins A1 then try do the same in a2 I I need to unlock the column and do the same for a3
 
Upvote 0
If you want to enter data in all the other columns, then unlock the entire sheet. You can do this quickly by clicking on the box in the upper left hand corner of the sheet. The box is above the row number 1 and to the left of the column letter A. This will select the entire sheet. Then right click on any cell and click 'Format cells', then the 'Protection' tab and then uncheck the 'Locked' box. Next protect the sheet. You will be able to enter data in any column without having to unprotect it. Keep in mind that when you enter data in column A, column B will be locked and vice versa.
 
Upvote 0
So in short I need to unlock a and b columm on then enter the date in a specific column and unlock the sheet again correct?
 
Upvote 0
Sorry for bathering you but maybe you know how to make something so the same data wont be entered in the other column. For example if you enter the value 151515 in column A then you cannot enter the same value in column B
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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