突出每隔一个可见的行

我试图在我运行一个包含总共0的隐藏行之后细条纹隔行。

我有一些代码做了一些条纹,但似乎不是每隔一个可见的行。

根据总的数量,销钉条纹将几乎斑点,有时它会看起来像附加的图片。

Sub Format_635() Application.ScreenUpdating = False Dim sht5 As Worksheet Set sht5 = ThisWorkbook.Worksheets("635 BOM") Call Unprotect sht5.Activate Dim lastRow As Long, lastCol As Long Dim rng As Range Dim WholeRng As Range With sht5 Set rng = Cells 'last row lastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row 'last column lastCol = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column Set WholeRng = Range(Cells(9, "A"), Cells(lastRow, lastCol)) WholeRng.Select With WholeRng With .Interior .PatternColorIndex = xlAutomatic .Color = RGB(255, 255, 255) .TintAndShade = 0 Range(Cells(9, "A"), Cells(lastRow, lastCol)).Borders(xlInsideHorizontal).LineStyle = xlContinuous Range(Cells(9, "A"), Cells(lastRow, lastCol)).Borders(xlInsideVertical).LineStyle = xlContinuous Range(Cells(9, "A"), Cells(lastRow, lastCol)).Borders(xlEdgeBottom).LineStyle = xlContinuous Range(Cells(9, "A"), Cells(lastRow, lastCol)).Borders(xlEdgeRight).LineStyle = xlContinuous End With End With With WholeRng For Each rng In WholeRng If WorksheetFunction.Ceiling(rng.Row - 2, 1) Mod 2 = 0 Then rng.Interior.Color = RGB(228, 223, 235) End If Next End With End With Call Protect sht5.Activate Call NoSelect Set rng = Nothing Set WholeRng = Nothing Application.ScreenUpdating = True End Sub 

例

谢谢

经过一些困难,我觉得我明白了。 你想交替你的可见行的内部颜色,但实际上你做的是基于.row属性,这是独立的可见/隐藏的行。 所以你的结果是偶数行用RGB(228, 223, 235)着色,而不pipe哪些行被隐藏。

没有太多的参与其余的例程,这些行应该是固定的:

 > With WholeRng > For Each rng In WholeRng > If WorksheetFunction.Ceiling(rng.Row - 2, 1) Mod 2 = 0 Then > rng.Interior.Color = RGB(228, 223, 235) > End If > Next > End With 

作为一个简单的修复,尝试改变上面的行到以下内容:

 Dim b As Boolean For Each rng In WholeRng.Rows If Not rng.Hidden Then If b Then rng.Interior.Color = RGB(228, 223, 235) b = Not b End If Next 

你可以做到这一点,没有代码,条件格式就足够了

  1. select行1到2(从A1开始select)
  2. 添加这个条件格式test =MOD(SUBTOTAL(103,A1:$A$1),2)=0

在这里输入图像说明

  • SUBTOTAL公式用于计算不是空白条目,它忽略隐藏的单元格。
  • MOD部分突出显示第二个可见行。