根据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
语句。)
- 使用jquery ajax和servlet导出为excel
- delphi – 确定如果Excel启用筛选器
- 插入新行并使用OpenXML SDK 2.0移动现有的行
- 从范围创build一个行数组(error handling)
- 如何使用“偏移”和“结束”(xlDown)来select要绘制的数据
- 如何编写公式将string数据(“yyyy.mm.dd”)转换为通用date格式(mm / dd / yyyy)?
- 如果两张纸张的值匹配,则添加新纸张
- 奇怪的输出在简单的function – Excel的VBA
- C#Excel COM互操作抛出exception“HRESULTexception:0x800A03EC”