【发布时间】:2012-03-09 12:02:58
【问题描述】:
以下 excel vba 代码将顶行中的日期与 E 和 F 列中的开始和结束日期进行比较。 然后突出显示单元格以在每行中生成一个颜色条。
如何跳过已经突出显示的行并在输入有效日期后自动创建彩色条?提前感谢您提供的任何帮助。
Set Rng = Range(Range("E7"), Range("E" & RowS.Count).End(xlUp)) 'The start end dates are in columns E and F
DateRng.Resize(Rng.Count + 1).Interior.ColorIndex = xlNone
For Each Dn In Rng
For Each Ac In DateRng
If Ac >= Dn And Ac <= Dn.Offset(0, 1) Then
Ac.Offset(Dn.Row - 2 - 0).Interior.ColorIndex = Range("D4").Value
Ac.Offset(Dn.Row - 2 - 0).Borders(xlEdgeTop).Color = vbWhite
Ac.Offset(Dn.Row - 2 - 0).Borders(xlEdgeTop).LineStyle = xlContinuous
Ac.Offset(Dn.Row - 2 - 0).Borders(xlEdgeTop).Weight = xlThick
Ac.Offset(Dn.Row - 2 - 0).Borders(xlEdgeBottom).Color = vbWhite
Ac.Offset(Dn.Row - 2 - 0).Borders(xlEdgeBottom).LineStyle = xlContinuous
Ac.Offset(Dn.Row - 2 - 0).Borders(xlEdgeBottom).Weight = xlThick
End If
Next Ac
Next Dn
V
【问题讨论】:
-
向我们展示完整的代码。 DateRng 在哪里声明?您还应该使用 Option Explicit 强制变量声明