【问题标题】:Highlight cell if the active cells (two or more rows) is in the same column如果活动单元格(两行或多行)在同一列中,则突出显示单元格
【发布时间】:2019-07-11 09:04:23
【问题描述】:

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

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

如何做到这一点,但有两行或更多行(5、7、9、11)

【问题讨论】:

  • 所以要明确一点,如果选择了 #、# 和 # 行,您希望这些行中的每一行都突出显示吗? (其中“#”是任意行号)
  • 如果我选择一个单元格会发生什么,例如第 5 行?
  • 使用此公式,如果我选择第 5 行中的单元格,例如 c5,则第 3 行中的单元格将更改填充颜色,此单元格将为 c3 .. 如果我选择多个单元格,我想行(例如 c11,或 c13,或 c21)到 c3 更改填充颜色.. 在这个网站上,我看到了这个公式是如何工作的 google.rs/amp/s/www.techrepublic.com/google-amp/blog/…

标签: excel excel-formula


【解决方案1】:

突出显示指定行中的单元格

  • 在 Visual Basic 编辑器中 (Alt+F11) 将此代码复制到工作表 要运行它的工作表的窗口(双击) 代码。
  • 调整常量部分的值(cRngcRangecRowcColor) 以满足您的需求。

代码

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

【讨论】:

    【解决方案2】:

    将您的条件格式设置为三个条件的 AND。

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

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

    【讨论】:

    • 我不太明白你的答案..你能写出完整的公式吗..所以我的条件格式选择是 C3:AM3 我想成为其中一部分的行是第 5 到 27 行..所有奇数行..谢谢
    • 这就是完整的公式。您在将 11 更改为 27 时遇到问题吗?
    • 公式不起作用..我会告诉你我的步骤..首先我选择 c3:am3,然后单击条件格式,然后单击新规则,然后使用公式确定要格式化的单元格。 . 然后我删除了我以前的公式并粘贴了你的.. 当我选择第 5 到 11 行中的单元格时,第 3 行中的单元格上没有任何东西
    • 我想我现在可能明白你在做什么了。您可能应该使用 worksheet_selectionchange。
    猜你喜欢
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    • 2016-01-17
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    相关资源
    最近更新 更多