【问题标题】:Excel conditional scale colors based on another value across split cellsExcel 条件缩放颜色基于拆分单元格中的另一个值
【发布时间】:2023-03-20 08:36:02
【问题描述】:

您好,我有一个问题正在努力解决。

我正在尝试根据 A 列中同一行的相应值,为各行中的单元格创建颜色的滑动比例。

例如:

在第一行,单元格 C1:E1,G1:J1 的单元格颜色应基于 A1 中的值和颜色图表中的相应颜色

在第二行中,单元格 C2:E2,G2:J2 的单元格颜色应基于 A2 中的值和颜色图表中的相应颜色 对于所有行(大约 500 行),这应该继续向下

图片前

后像示例

【问题讨论】:

    标签: excel colors formatting conditional-statements scale


    【解决方案1】:

    我的解决方案是使用具有与色标相对应的值的辅助表。然后在原始表上应用条件格式,但使用辅助表中的值。它很简单,不需要宏,但您需要一个辅助表(以及它的空间)。

    【讨论】:

      【解决方案2】:
      Option Explicit
      Sub ApplyConditionalFormatting()
          Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") ' change to your sheet here
          Dim rw As Long
          Dim rng As Range
      
          For rw = 3 To 8 ' change to your respective rows
              With ws
                  Set rng = .Range(.Cells(rw, "E"), .Cells(rw, "K")) ' change to your respective columns
      
                  With rng
                      .FormatConditions.AddColorScale ColorScaleType:=3
                      .FormatConditions(.FormatConditions.Count).SetFirstPriority  ' now its index is 1, in case there already was cond formatting applied
                  End With
      
                  With rng.FormatConditions(1)
                      With .ColorScaleCriteria(1)
                          .Type = xlConditionValueNumber
                          .Value = 0
                          .FormatColor.Color = 7039480
                      End With
      
                      With .ColorScaleCriteria(2)
                          .Type = xlConditionValueFormula
                          .Value = "='" & ws.Name & "'!$D$" & rw & "*3" ' References column D, change as needed
                          .FormatColor.Color = 8711167
                      End With
      
                      With .ColorScaleCriteria(3)
                          .Type = xlConditionValueFormula
                          .Value = "='" & ws.Name & "'!$D$" & rw & "*5" ' References column D, change as needed
                          .FormatColor.Color = 8109667
                      End With
                  End With
              End With
          Next rw
      End Sub
      

      【讨论】:

      • 你能再解释一下吗?这些颜色值是什么?
      • 我们通常需要一些 cmets,而不仅仅是解决方案。我们希望人们尝试理解问题和解决方案,而不是盲目复制答案。
      猜你喜欢
      • 2015-11-29
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2010-10-31
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多