起點!!
在表日後事項:
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」。
可能的重複[Excel - 條件格式。引用一個樣式化的單元格而不是固定的格式化](http://stackoverflow.com/questions/25538313/excel-conditional-formatting-referring-to-a-styled-cell-instead-of-having-fix) – pnuts 2014-09-01 12:50:22