【发布时间】:2014-07-14 14:50:40
【问题描述】:
我正在尝试根据 COL B、C、D 的行颜色为 A 列中的每一行着色。
说 A2 颜色是基于 B2,C2,D2 的颜色。如果其中任何一个为红色,则 A2 应为红色,否则 A2 为绿色
请在下面找到我的代码:
Option Explicit
Sub Sheet1()
Dim lastR As Long
Dim i As Long
lastR = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = lastR To 2 Step -1
If ((Sheets("Sheet1").Cells(i, "B")) Or (Sheets("Sheet1").Cells(i, "C")) Or (Sheets("Sheet1").Cells(i, "D"))) = Rows(i).Interior.Color = RGB(255, 0, 0) Then
Rows(i).Interior.Color = RGB(0, 255, 0)
End If
Next i
End Sub
我的下标超出范围,错误代码 9。
这是我的 excel 屏幕打印:
【问题讨论】: