excel中vba锁定和解锁

2025-01-05 05:36:44
推荐回答(4个)
回答1:

你少了一句end if
ActiveSheet.Unprotect
Cells.Locked = False '先把所有单元格设置为不锁定的
For i = 3 To 63
If Cells(i, 1) = "正确" Then Cells(i, 2).Locked = True
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

也可以改成以下代码
ActiveSheet.Unprotect
Cells.Locked = False '先把所有单元格设置为不锁定的
For i = 3 To 63
If Cells(i, 1) = "正确" Then Cells(i, 2).Locked = True
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

回答2:

……撤消工作表保护……
for i=3 to 63
if range("A" & i)="正确" then range("B" & i).locked=true
next
……保护工作表……

没写的自己补咯

回答3:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
If Cells(ActiveCell.Row, ActiveCell.Column - 1).Value = "确定" Then
Cells(ActiveCell.Row, ActiveCell.Column - 1).Select
end if
End Sub

回答4:

VBA中如何根据两个单元格的输入情况来确定第三个单元格的显示内容?比如我在Private Sub ComboBox1_Change() If ComboBox1.Text = "太阳" And Combo