我正在尝试编写宏来对用两种颜色(白色/ RGB(255,255,255)或浅黄色/ RBG(255,255,238)之一填充的行进行分组。但是当我运行宏时,它只会将浅黄色行分组。
固定代码(感谢@Vityata):
Option Explicit
Sub RowGrouper()
Dim rng As Range
Dim lastRow As Long
lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For Each rng In Range(Cells(10, 1), Cells(lastRow, 1)).Cells
If rng.Interior.Color = RGB(255, 255, 255) Or rng.Interior.Color = RGB(255, 255, 238) Then
rng.Rows.Group
End If
Next
End Sub
最终结果应如下所示:
感谢您能给我任何帮助。
答案 0 :(得分:3)
从此:
rng.Interior.ColorIndex = rng.Interior.Color = RGB(255, 255, 255)
写下:
rng.Interior.Color = RGB(255, 255, 255)
答案 1 :(得分:1)
试一下-我发现在分组之前先概述整个范围比较容易。
我看到Vityata找到了错字,但是我已经仍然发布了我的解决方案! :)
Option Explicit
Sub RowGrouper()
Dim i As Long, j As Long, lastRow As Long
lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 10 To lastRow
For j = i To lastRow
If Cells(j, 1).Interior.Color <> RGB(255, 255, 255) And Cells(j, 1).Interior.Color <> RGB(255, 255, 238) Then
If j <> i Then
Rows(i & ":" & j - 1).Rows.Group
i = j
Exit For
Else
i = i + 1
End If
End If
Next j
Next
End Sub