Locking Cells Using VB or Formula

JohnH

New Member
Joined
Feb 26, 2002
Messages
3
Is there a way to lock cells using VB based on the value of another cell. Example:

I have a list for data entry, if the value of the first cell in the row (A2)is equal to the value of the first row (A1) then I want to lock Cells C2 and D2. This will apply for all subsequent rows as data is entered.

What is the best way of doing this?


Thanks.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You may be able to use data validation for this. Go to your cell you want to lock, and choose validation from the data menu. On the setting tab, change the allow drop down to custom. Type in =A2<>A1 under the formula. You can also add custom input and error messages here if you choose.

Be aware that this will prevent a user from typing in a value if A1=A2, but it will not prevent a user from pasting a value here. If you need something more robust, VBA is needed.

Good luck.

On 2002-02-27 07:26, JohnH wrote:
Is there a way to lock cells using VB based on the value of another cell. Example:

I have a list for data entry, if the value of the first cell in the row (A2)is equal to the value of the first row (A1) then I want to lock Cells C2 and D2. This will apply for all subsequent rows as data is entered.

What is the best way of doing this?


Thanks.
This message was edited by IML on 2002-02-27 07:37
 
Upvote 0
On 2002-02-27 07:26, JohnH wrote:
Is there a way to lock cells using VB based on the value of another cell. Example:

I have a list for data entry, if the value of the first cell in the row (A2)is equal to the value of the first row (A1) then I want to lock Cells C2 and D2. This will apply for all subsequent rows as data is entered.

What is the best way of doing this?


Thanks.

Thank you both for the reply. The best solution for my purpose is using the Data Validation method.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,223,323
Messages
6,171,467
Members
452,406
Latest member
kken tthompson

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