Excel 2010条件格式设置单个行

Excel 2010条件格式设置单个行,excel,excel-2010,rows,conditional-formatting,vba,Excel,Excel 2010,Rows,Conditional Formatting,Vba,我试图在844行不同的行上使用条件格式(绿色-黄色-红色色标)来跟踪过去六年(年份为列)的优质量。每个卷列之间的棘手部分是项目数。我想将每一行的格式设置为premium volume,并保持项目数量不变 此时,我通过按住ctrl键,然后选择条件格式来选择每个高级卷单元 我正在尝试将其自动化,这样我就不必为844行和未来的电子表格继续这个过程 我附上了工作表的图片供您参考 非常感谢您的帮助 谢谢 布拉德 通过运行宏记录器,我获得了一些条件格式的基本代码。我用rng变量替换了所有出现的选择,并将rn

我试图在844行不同的行上使用条件格式(绿色-黄色-红色色标)来跟踪过去六年(年份为列)的优质量。每个卷列之间的棘手部分是项目数。我想将每一行的格式设置为premium volume,并保持项目数量不变

此时,我通过按住ctrl键,然后选择条件格式来选择每个高级卷单元

我正在尝试将其自动化,这样我就不必为844行和未来的电子表格继续这个过程

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

非常感谢您的帮助

谢谢

布拉德


通过运行宏记录器,我获得了一些条件格式的基本代码。我用
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
我不知道行的限制是什么,但1000行对我来说很好