2012-02-18 104 views
1

以下Excel VBA代码在顶行与列E和F 开始和结束日期,然后它突出了细胞产生各行中的颜色栏比较日期。Excel VBA中 - 跳过行已经强调

如何跳过已突出显示的行并在输入有效日期后自动创建彩色栏?提前感谢您提供的任何帮助。

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

+0

向我们展示了完整的代码。 DateRng在哪里宣布?你也应该使用显式的选项来强制变量声明 – JMax 2012-02-18 11:33:33

回答

2

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

然后在你的代码的任何地方,你想跳过/基于格式,你可以简单地问如果样式(或样式)的有效期为当前单元格做这样做:

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

检查多个不同的样式可以使用集合或脚本字典通过函数测试所有样式。让我知道你是否想进一步详细说明如何工作。