Home > Back-end >  Is there any way that I can lock excel cell if it has value?
Is there any way that I can lock excel cell if it has value?

Time:11-12

Is there any way to lock the excel cell if it has value and unlock it if it has no value contained?

e.g. if Persone updates the excel-sheet and sends it to another person, the second person only allows the update blank cells.

CodePudding user response:

LEt's say your data is they grey zone in the image below:

enter image description here

You want to lock all grey cells with values and keep unlocked the empty white cells. Manually, you can do it like this:

  1. Select all grey zone (your whole dataset)
  2. Right click--> Format Cells enter image description here
  3. A dialog box appears. Go to tab protect and make sure checkbox locked is checked! enter image description here
  4. Close dialog box
  5. Select again all grey zone (your whole dataset)
  6. In the upper option ribbon, go to tab Start and search for option Find & Select and then enter image description here

    1. Select option enter image description here

      1. Now repeat steps 2 to 4 but selection option unlocked in step 3

      Now your empty cells are unlocked and nonempty cells are locked. Make sure you

      Every time a cell is changed, if the cell ends up with a value in it, then it will lock that cell.

      Private Sub Worksheet_Change(ByVal Target As Range)
          
          If Not Target.Value = "" Then
              ActiveSheet.Unprotect
              Target.Locked = True
              ActiveSheet.Protect
          End If
      End Sub
      

      It does mean you can enter values into a cell exactly once, and then you have to unprotect the sheet to delete the values entered. not exactly the solution you are after I fear...

  • Related