我目前有下面的代碼。如果單元格爲空白,則填充爲綠色(4)。當單元格不是空白時,將沒有填充。但是如果我希望我的單元格填充爲黃色(如果單元格值=「是」),則我的單元格格式爲(0,3)?目前有一個「是」或「否」的下拉菜單。如何應用填充顏色取決於單元值使用VBA
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 9
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 = 10 To 15
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
Else
For i = 1 To 15
With Target.Offset(0, i)
.Value = ""
.Locked = True
.FormatConditions.Delete
End With
Next i
End If
ActiveSheet.Protect
End If
End Sub
的另外還有一種細胞和偏移,其中一個意思之間的差異? (另外,沒有'Cell(0,27)',索引開始'1' –