我知道如何使用单个活动行的条件格式来突出显示单元格
=CELL("address")=CELL("address",C$5)
怎么做但有两行或更多行(5,7,9,11)
将条件格式基于三个条件的AND。
=and(row()>=5, row()<=11, mod(row(), 2)=1)
更新版本的Excel可以使用isodd(row())
而不是mod(row(), 2)=1
。
cRng
,cRange
,cRow
cColor
)以满足您的需求。Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const cRng As String = "C3:AM3" ' Target Range
Const cRange As String = "C5:AM27" ' Source Range
Const cRow As Long = 3 ' Target Row Number
Const cColor As Long = 3 ' Color Index e.g. 3 is Red.
Dim rng As Range ' Intersect Range
Dim i As Long ' Rows Counter
Dim k As Long ' Areas Counter
' Create a reference to Intersect Range.
Set rng = Intersect(Target, Range(cRange))
' Remove color in all cells of Target Range.
Range(cRng).Interior.ColorIndex = xlNone
If Not rng Is Nothing Then
' Loop through Areas of Intersect Range.
For k = 1 To rng.Areas.Count
' Loop through rows of current Area of Intersect Range.
For i = 1 To rng.Areas(k).Rows.Count
' In current Area of Intersect Range
With rng.Areas(k)
' Check if current row number of current area of Intersect
' range is odd.
If .Rows(i).Row Mod 2 = 1 Then
' Apply color to all cells in row cRow of Worksheet
' whose columns are the same as those of Current Area
' of Intersect Range.
Cells(cRow, .Column).Resize(, .Columns.Count) _
.Interior.ColorIndex = cColor
Exit For
End If
End With
Next ' Row of current Area of Intersect Range.
Next ' Area of Intersect Range.
End If
End Sub