View Single Post
 
Old 03-26-2017, 04:42 PM
Logit Logit is offline Windows 10 Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

This version allows you to double-click the cell, enter the password, then change the data there in. Keeps you from having to constantly go to the Menu Bar to enter a password.

Code:
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim PassWord As String, i As Integer
  i = 0
  Do
    i = i + 1
    If i > 3 Then
      MsgBox "Sorry, Only three tries"
        Application.DisplayAlerts = False
        ThisWorkbook.Saved = True
        Application.Visible = False
        Application.Quit
      Exit Sub
    End If
    PassWord = InputBox("Enter Password")
    Loop Until PassWord = "password"
    If PassWord = "password" Then
    Dim cel As Range
    ActiveSheet.Unprotect PassWord:="password"
    For Each cel In Target
        If cel.Value <> "" Then
            cel.Locked = True
        End If
    Next cel
    End If
  
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
   Dim cel As Range
    ActiveSheet.Unprotect PassWord:="password"
    For Each cel In Target
        If cel.Value <> "" Then
            cel.Locked = True
        End If
    Next cel
    ActiveSheet.Protect PassWord:="password"
End Sub
Attached Files
File Type: xlsm Cell Password Protect.xlsm (17.0 KB, 9 views)
Reply With Quote