-1

I would like to lock a cell depending on the value in another cell.

Example:

Lock A2 if B2 has any value with a minimum of 10 letters in it and unlock A2 if B2 has a value with more than 10 letters.

I would like to have this in column A and B, so the VBA-macro will look at the value in column B and lock/unlock the value in column A accordingly.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ezzat
  • 1

1 Answers1

0

Set all of your sheet to unlock state first.

Then use to lock a specific cell according to a value in another cell

If Worksheets("Sheet1").Range("B1").Value = <something> then: _
Worksheets("Sheet1").Range("A1").Locked = True

Put that into a loop and you have what you want.

In the end to make the lock effective and still allow your VBA code to modify the cells is:

Worksheets("Sheet1").Protect UserInterfaceOnly:=True

It will lock only the cells you marked above with lock and leave all others unlocked.

Blenikos
  • 733
  • 10
  • 19
  • My knowledge in VBA is still limited. I don't know how to put that in a loop, could you help me? – Ezzat Oct 20 '16 at 09:53
  • Firstly start by learning vba. Loop is a really basic function in every language and you cannot go very far if you don't know how to loop. For this time only look here: http://stackoverflow.com/questions/3875415/loop-through-each-cell-in-a-range-of-cells-when-given-a-range-object And remember that google is always your friend for that kind of questions, use it more! – Blenikos Oct 20 '16 at 10:06
  • As I understand it you are really new in Stack Overflow so welcome to the community. Please take the tour here: http://stackoverflow.com/tour It will really help you on how to ask questions and navigate here. – Blenikos Oct 20 '16 at 10:11