我正在尝试在运行包含总共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
Thx
答案 0 :(得分:1)
经过一些困难后我觉得我明白了。您希望替换可见行的内部颜色,但实际上您所做的是基于.row
属性,该属性独立于可见/隐藏行。因此,无论隐藏哪些行,您的结果都是使用RGB(228, 223, 235)
对偶数行进行着色。
如果没有太多参与其他日常工作,这些行应该修复:
> 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 :(得分:1)