如果活动单元格(两行或更多行)位于同一列中,则突出显示单元格

问题描述 投票:2回答:2

我知道如何使用单个活动行的条件格式来突出显示单元格

=CELL("address")=CELL("address",C$5)

怎么做但有两行或更多行(5,7,9,11)

excel excel-formula
2个回答
0
投票

将条件格式基于三个条件的AND。

=and(row()>=5, row()<=11, mod(row(), 2)=1)

更新版本的Excel可以使用isodd(row())而不是mod(row(), 2)=1


0
投票

Highlight Cells in Specified Row

  • 在Visual Basic编辑器(Alt + F11)中将此代码复制到要运行此代码的工作表的工作表窗口(双击)。
  • 调整常量部分中的值(cRngcRangecRow 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
© www.soinside.com 2019 - 2024. All rights reserved.