我有一個手錶範圍,某些單元格突出顯示爲黃色。對於這些單元中的每一個,都有一個對應的參考值,全部位於一列內。使用參考範圍的Excel條件格式化
我想突出顯示目標範圍內的所有單元格red
,對應的參考單元格中的值與目標單元格中的值匹配。
我想到的代碼如下,但有一些我無法修復的編譯錯誤。顯然,手錶範圍不能包含「多個範圍」。
Sub Highlight_pairAB()
Dim WatchRange As Range, Target As Range, cell As Range, ref As Range
Set Target = Range("Y3:Y274", "AC3:AC274") 'change column ref as required
Set WatchRange = Range("B3:B274", "E3:E274", "H3:H274", "K3:K274")
Set RefRange = Range("A3:A102")
For Each cell In Target.Cells
If Application.WorksheetFunction.CountIf(WatchRange, cell.Value) > 0 Then
cell.Interior.ColorIndex = 3
For Each watchCell In WatchRange.Cells
If watchCell.Interior.ColorIndex = 6 And RefRange.Value = Target.Value Then: targetCell.Interior.ColorIndex = 3
Next watchCell
Else: cell.Interior.ColorIndex = xlNone
End If
Next cell
End Sub
我試過這之前發佈,它沒有奏效。 – 2009-10-15 01:39:49