I have protected my worksheet during workbook_open() event. Using Worksheet_SelectionChange, when user selects a cell, a popup date picker appears to capture date from the user and enter it into that respective protected cell.
My requirement is, I want to provide access to users where they can delete the date / content inside the cell but not make to edit it. I tried using worksheet.Protect methods. But they didn't suit my particular need.
Please help. The code i used,
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set wb = ThisWorkbook
Set ws0 = wb.Worksheets("DB")
Set ws1 = wb.Worksheets("Design-HW")
rowposition = 4
productno = ws1.Cells(Rows.Count, ws0.Range("A4").Value).End(xlUp).Row 'to find the number of rows in product no column
Set datesrange = ws1.Range(ws1.Cells(rowposition + 2, ws0.Range("H4").Value), ws1.Cells(productno, ws0.Range("P4").Value + 1))
If Not Application.Intersect(datesrange, Target) Is Nothing Then
Call ShowUserform 'Calls popup date picker and the date user selects is entered in the ws0.Range("H1")
If ws0.Range("H1").Value <> "" Or ws0.Range("H1").Value <> Empty Then
Application.EnableEvents = False
ws1.Unprotect Password:="1234"
ws1.Cells(Target.Row, Target.Column).Locked = False
ws1.Cells(Target.Row, Target.Column).Value = ws0.Range("H1").Value
ws1.Cells(Target.Row, Target.Column).Locked = True
ws1.Protect Password:="1234", UserInterfaceOnly:=True, AllowFiltering:=True, AllowFormattingCells:=True, _
AllowDeletingRows:=True
ws0.Range("H1").Value = Empty
Application.EnableEvents = True
' GoTo exitingdate:
End If
End If
End Sub