【发布时间】:2022-01-01 10:21:56
【问题描述】:
我为第一组列 (C:E) 创建了条件格式(见图 3)。
Range("C1:E36").Select
Selection. Format Conditions. Add Type:=xlExpression, Formulal:="=$D6=""Sun"""
Selection. Format Conditions (Selection. FormatConditions. Count).SetFirstPriority
with Selection. Format Conditions (1). Interior
.Pattern = xlLightVertical
. PatternColor = 65535
.ColorIndex = xlAutomatic
.PatternTintAndShade = 0
End With
我正在尝试创建一个 for 循环,它应该应用于所有 12 个集合 - 每个集合有 3 列(参见图 2)。此外,它应该运行 3 次 - 从行 C6, C45,C84 开始 - 对应于我试图显示的三年(见图 1)。我正在为 for 循环而苦苦挣扎。以及条件格式中$D6 列的相对绝对引用以及如何使其成为$G6, $J6, $D84, $G84。
For o = 1 TO 3 Step 1
For I = 1 To 12 Step 1
Range (.Cells(6, I * 3), .Cells (36, I * 3 + 2)).Select
Selection. Format Conditions. Add Type:=xlExpressionFormulal:="=$D6=""Sun"""
Selection. Format Conditions (Selection. Format Conditions. Count).SetFirstPriority
With Selection. Format Conditions (1). Interior
.Pattern = xlLightvertical
.PatternColor = 65535
.ColorIndex = xlAutomatic
.PatternTintAndShade = 0
End With
Next I
Next o
End Sub'
【问题讨论】:
-
没有代码图片。请编辑帖子以将代码包含为文本。对于代码格式化,在代码块前后的单独行上使用代码围栏```。
-
手动复制前三列并三三粘贴不起作用吗?
标签: excel vba for-loop reference