从for循环中访问范围的下一个项目(Excel VBA)

我有一个过滤的电子表格,没有明显的模式。 我需要检查是否有两个连续的单元格灰色填充(RGB:191,191,191)。 当我连续说,我的意思是在可见的单元格,这样连续不一定意味着行号将是连续的。 但是我不确定如何访问for循环中的下一行范围。 我复制并粘贴了脚本的简化版本以帮助解答。 谢谢

Set Rng = Range("A2:A105").SpecialCells(xlCellTypeVisible) For Each rowcheck In Rng If Cells(rowcheck.Row, "C").Interior.color = RGB(191, 191, 191) And _' 'The next visible cell also has an rgb value of 191 Then blah blah End If Next rowcheck 

做两遍:

  1. 获取信息
  2. 循环信息

例如:

 Sub dural() Dim boo() As Boolean, Rng As Range, i As Long, iMax As Long Set Rng = Range("A2:A105").SpecialCells(xlCellTypeVisible) ReDim boo(1 To Rng.Count) i = 1 For Each rowcheck In Rng If Cells(rowcheck.Row, "C").Interior.Color = RGB(191, 191, 191) Then boo(i) = True Else boo(i) = False End If i = i + 1 Next rowcheck iMax = i - 2 For i = 1 To iMax If boo(i) And boo(i + 1) Then 'whatever End If Next i End Sub