2010年Excel个别行条件格式化

4
我尝试在844个独特的行上使用条件格式(绿色-黄色-红色渐变)来跟踪过去六年的保费总额(年份为列)。这里的棘手之处在于每个保费列之间都有项目数。我想格式化每一行的保费总额,同时保留项目数不变。
目前,我通过按住Ctrl并选择条件格式来选择每个单独的保费单元格。
我希望自动化此过程,以便我不必为844行和未来的电子表格继续执行此过程。
我附上工作表的图片供您参考。
非常感谢任何帮助!!!
谢谢,
Brad
1个回答

1

我通过运行宏录制器获得了一些基本的条件格式化代码。我用rng变量替换了所有选择的出现,并将该rng变量设置为子程序的参数,以便可以在循环中调用该子程序:

Sub SetRangeCF(rng As Excel.Range)

rng.FormatConditions.AddColorScale ColorScaleType:=3
rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
rng.FormatConditions(1).ColorScaleCriteria(1).Type = _
xlConditionValueLowestValue
With rng.FormatConditions(1).ColorScaleCriteria(1).FormatColor
    .Color = 8109667
    .TintAndShade = 0
End With
rng.FormatConditions(1).ColorScaleCriteria(2).Type = _
xlConditionValuePercentile
rng.FormatConditions(1).ColorScaleCriteria(2).Value = 50
With rng.FormatConditions(1).ColorScaleCriteria(2).FormatColor
    .Color = 8711167
    .TintAndShade = 0
End With
rng.FormatConditions(1).ColorScaleCriteria(3).Type = _
xlConditionValueHighestValue
With rng.FormatConditions(1).ColorScaleCriteria(3).FormatColor
    .Color = 7039480
    .TintAndShade = 0
End With
End Sub

然后在循环中调用上述子程序,对于任何在A列中有值的行,此处仅调用一次。这假定条件格式从第2行开始,并且您在A列中具有不间断的数据。如果不是这样,您需要调整此循环代码:

Sub SetEachRow()
Dim ws As Excel.Worksheet
Dim LastRow As Long
Dim cell As Excel.Range

Set ws = ActiveSheet    'change as necessary
With ws
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    For Each cell In .Range("A1:A" & LastRow)http://stackoverflow.com/questions/10245638/excel-changes-conditional-formatting-formula?rq=1
        cell.EntireRow.FormatConditions.Delete
        SetRangeCF cell.EntireRow
    Next cell
End With
End Sub

我不知道这个方法适用于多少行,但是对于1,000行来说,它可以正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接