根据具有2个条件的excel vba中的数据条件更改某些行颜色,1可以覆盖另一个

时间:2016-11-06 22:56:44

标签: excel vba excel-vba

我必须在此处着色细胞水平。第一个是将剩余0个月库存的行更改为黄色单元格。接下来是更改Item状态为expired,hold或restricted的行。如果出现这种情况,绿色会覆盖黄色。我希望它只在数据范围内着色,即A-O列。我知道我的代码并不太远,只需要一些调整。还想知道我是否以正确的顺序列出它们的事实将产生适当的绿色覆盖黄色。

    'Months of stock remaining @ <1 to yellow cell=========================

Set MoSR = Range("M7:M" & Cells(Rows.Count, "A").End(xlUp).Row)
    For Each Cell In MoSR
        Select Case Cell.Value
            Case Is = "<1"
                .Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .Color = 10092543
        End Select
    Next

'Item status of expired,hold,and restricted to green cell==============

Set Istatus = Range("C7:C" & Cells(Rows.Count, "A").End(xlUp).Row)
    For Each Cell In Istatus
        Select Case Cell.Value
            Case Is = "Expired,Hold,Restricted"
                .Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .ThemeColor = xlThemeColorAccent6
                .TintAndShade = 0.599993896298105
        End Select
    Next

我已将代码编辑为更准确

1 个答案:

答案 0 :(得分:2)

sys.path

(在看到Thomas Inzina的回答后编辑修复了'Months of stock remaining @ <1 to yellow cell========================= Set MoSR = Range("M7:M" & Cells(Rows.Count, "A").End(xlUp).Row) For Each Cell In MoSR Select Case Cell.Value 'Use the next statement if the cell contains a number such as 0 Case Is < 1 'Use this statement if the cell actually contains a string of "<1" 'Case Is = "<1" With Range("A" & Cell.Row & ":O" & Cell.Row).Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 10092543 End With End Select Next 'Item status of expired,hold,and restricted to green cell============== Set Istatus = Range("C7:C" & Cells(Rows.Count, "A").End(xlUp).Row) For Each Cell In Istatus Select Case Cell.Value Case "Expired", "Hold", "Restricted" With Range("A" & Cell.Row & ":O" & Cell.Row).Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent6 .TintAndShade = 0.599993896298105 End With End Select Next 声明。)