起点!!
在工作表事件中:
Private Sub Worksheet_Change(ByVal Target As Range)
ApplyCond Range("K" & Target.Row)
End Sub
在一个模块中:
Public Sub ApplyCond(xx As Range)
If xx.Value = "" Then Exit Sub
xx.FormatConditions.Delete
xx.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:=xx.Value
kk = Split(xx.Value)
a = -1
b = -1
For i = LBound(kk) To UBound(kk)
Select Case kk(i)
Case "Dead": a = 4
Case "Alive": a = 5
Case Else
For e = 3 To 9999
If Range("B" & e).Value = "" Then Exit For
If Range("B" & e).Value = kk(i) Then
b = e
End If
Next
End Select
Next
' Apply Format
On Error Resume Next
If (a > 0) And (b > 0) Then
With xx.FormatConditions(1).Interior
.PatternColorIndex = Cells(b, a).Interior.PatternColorIndex
.Color = Cells(b, a).Interior.Color
.TintAndShade = Cells(b, a).Interior.TintAndShade
.Pattern = Cells(b, a).Interior.Pattern
.PatternThemeColor = Cells(b, a).Interior.PatternThemeColor
.ThemeColor = Cells(b, a).Interior.ThemeColor
.PatternTintAndShade = Cells(b, a).Interior.PatternTintAndShade
End With
With xx.FormatConditions(1).Font
.Bold = Cells(b, a).Font.Bold
.Italic = Cells(b, a).Font.Italic
.Underline = Cells(b, a).Font.Underline
.Strikethrough = Cells(b, a).Font.Strikethrough
.ThemeColor = Cells(b, a).Font.ThemeColor
.TintAndShade = Cells(b, a).Font.TintAndShade
.Color = Cells(b, a).Font.Color
.TintAndShade = Cells(b, a).Font.TintAndShade
End With
End If
End Sub
您需要验证拆分公式。也许使用 LCase 函数或其他过滤器会更好。
在我的函数中,我不使用“C”列。