【发布时间】:2017-10-08 19:34:20
【问题描述】:
我正在尝试仅使用 Excel 宏中的条件格式突出显示可见单元格每行的前 2 个值。我的范围是动态的,因此我正在运行一个循环以到达范围的最后一个单元格。
这是我的代码:
With Sheets("pcSupplyChainAnalysis").Select
For i = 2 To ctr
Set rng = Range("C" & i & ":" & "I" & i).SpecialCells(xlCellTypeVisible)
rng.FormatConditions.AddTop10
rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
With rng.FormatConditions(1)
.TopBottom = xlTop10Top
.Rank = 2
.Percent = False
End With
With rng.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
rng.FormatConditions(1).StopIfTrue = False
Next
End With
Ctr 是一个计数器,我正在运行以查找最后一个非空白单元格的位置,因为我的数据也有空白值,我正在使用宏从另一张表中复制它。
ctr = 2
Do While (ActiveSheet.Range("A" & ctr).Value <> "")
ctr = ctr + 1
Loop
ctr = ctr - 1
ActiveSheet.Range("B2:I" & ctr).Select
Selection.Cut
Range("C2:J" & ctr).Select
ActiveSheet.Paste
【问题讨论】: