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

我必须在这里着色细胞的水平。 第一个是将0个月的库存更改为黄色单元格。 接下来是更改Item状态为过期,保持或限制的行。 如果出现这种情况,绿色会覆盖黄色。 我希望它只在数据范围内着色,即列AO。 我知道我的代码不是太遥远,只需要一些调整。 还有人想知道,如果我把它们按照正确的顺序排列的话,将会产生适当的绿色覆盖。

'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 

我编辑的代码是更精确一点

 '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 

(在我看到Thomas Inzina的回答之后,编辑修改了Case语句。)