如何解决受保护单元格上的清除内容 - VBA
我在 workbook_open() 事件期间保护了我的工作表。使用 Worksheet_SelectionChange,当用户选择一个单元格时,会出现一个弹出日期选择器来捕获用户的日期并将其输入到相应的受保护单元格中。
我的要求是,我想为用户提供访问权限,让他们可以删除单元格内的日期/内容,但不能进行编辑。我尝试使用 worksheet.Protect 方法。但它们不适合我的特殊需求。
请帮忙。我使用的代码,
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。