2013-01-17 32 views
2

我试图在844个不同的行上使用条件格式(绿色 - 黄色 - 红色色标)来跟踪过去六年(年为列)的保费量。这是每个卷列之间棘手的部分是项目数量。我想格式化每行以获得额外的音量,并保持项目数量不变。Excel 2010有条件格式化单个行

在这一点上,我选择每个单独的高级卷单元格,方法是按住Ctrl并选择条件格式。

我试图自动化这个,所以我不必为844行和未来的电子表格继续这个过程。

我附上了工作表的图片供您参考。

任何帮助非常感谢!

感谢,

布拉德

enter image description here

回答

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对我来说工作得很好。