我有一个电子表格,显示一系列产品的库存数据。我每天都有一个专栏,其中的值显示我的库存水平将如何随着时间的推移而减少。
我想使用色标来轻松查看某些产品的库存何时会变少。我的量表的最小值、中值和最大值基于不同列中的值,并且每个产品的值都不同。根据它是中点还是最大值,它会相乘。不幸的是,色标不支持相对引用,这意味着我必须从第一行复制条件格式,并更改每隔一行的最小、中点和最大点引用。因为我的工作表上有数百行,有办法解决这个问题吗?
这就是我目前所拥有的:
当我尝试编辑第二行的条件格式时,我可以看到中点和最大点引用仍然来自上面的行,因为它们是绝对引用:
您需要为每一行制定一个单独的规则,并且可以使用以下命令自动创建这些规则vba /questions/tagged/vba.
下面的代码调整公式中的行号=$D$3*3
and =$D$3*5
。注释指出了您可能需要更改工作表名称、行数和列字母的位置。
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
Before
After- 显示第 8 行的规则;注意公式指的是$D$8
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)