excel中vba锁定和解锁

问题:当A3到A63这些单元格中有数值=“正确”的单元格,则自动锁定这个单元格前面一个单元格。比如:如果是A8=“正确",则B8就锁定。其他单元格也是这样。
帮忙看看怎么不行啊?(我是菜鸟)
ActiveSheet.Unprotect
for i=3 to 63
if range("A" & i)="正确" then
range("B" & i).locked=true
Else
Range("B" & i).Locked = False
next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

第1个回答  2011-11-25
你少了一句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个回答  2011-11-24
……撤消工作表保护……
for i=3 to 63
if range("A" & i)="正确" then range("B" & i).locked=true
next
……保护工作表……

没写的自己补咯
第3个回答  2011-11-24
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个回答  2011-11-24
VBA中如何根据两个单元格的输入情况来确定第三个单元格的显示内容?比如我在Private Sub ComboBox1_Change() If ComboBox1.Text = "太阳" And Combo
相似回答