Excel VBA – 跳过已经突出显示的行

下面的excel vba代码将顶行中的date与列E和F中的开始和结束date进行比较。然后突出显示单元格,以在每行中生成彩条。

如何跳过已突出显示的行,并在input有效date后自动创build彩色栏? 预先感谢您提供的任何帮助。

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

我的解决scheme(当然有许多不同的方法来解决这个问题)。 将会创build一个包含要使用的格式的样式(或样式)。

然后,在代码中您想跳过/根据格式设置的任何位置,可以通过执行以下操作简单地询问样式(或样式)是否对当前单元格有效:

 If Ac.style = "MyStyle" Then ' do stuff Else ' do other stuff end if 

要检查多种不同的样式,可以使用集合或脚本字典通过函数来​​testing所有样式。 让我知道如果你想进一步细节如何工作。