我目前的选择为"是"或"否"在A栏中。
让我们说当我选择"是"在A1中,强制单元格将填充绿色,并且当该强制单元格上有值时将删除填充。另外,我想在用户选择"是"的ROW上锁定我们不需要的单元格。我们怎样才能阻止用户在进入下一行之前跳过强制单元?是否可以显示一个消息框,提示用户输入值。
**Mandatory Cells**: A9, AB1 and BV1
**Cell need to be locked**: AB1, B1 and AA1
我的代码如下:
代码的当前行为:
当我选择"是"它将填充从A列到B列的单元格,颜色为绿色
Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(target, Range("A:A")) Is Nothing Then
ActiveSheet.Unprotect
If target = "Yes" Then
For i = 1 To 73
With target.Offset(0, i)
.Locked = False
.FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & target.Offset(0, i).Address & ")"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
.Interior.ColorIndex = 4
End With
End With
Next i
ElseIf target = "No" Then
For i = 1 To 73
With target.Offset(0, i)
.Value = ""
.Locked = True
.FormatConditions.Delete
End With
Next i
End If
ActiveSheet.Protect
End If
End Sub