[英]Access next item of a range from within a for loop (Excel VBA)
I have a filtered spreadsheet that has no obvious pattern to it. 我有一个过滤的电子表格,没有明显的模式。 I need to check whether there are two consecutive cells with grey fill (RGB : 191,191,191).
我需要检查是否有两个连续的单元格用灰色填充(RGB:191,191,191)。 When I say consecutive, I mean out of the visible cells, so consecutive doesn't necessarily mean the row numbers will be consecutive.
当我说连续时,我的意思是在可见的单元格之外,因此连续并不一定意味着行号将是连续的。 However I'm not sure how to access the next row of the range from inside the for loop.
但是我不确定如何从for循环内部访问范围的下一行。 I've copied and pasted a simplified version of my script to aid answers.
我已经复制并粘贴了脚本的简化版本以帮助解答。 Thanks
谢谢
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
Do it in two passes: 分两步进行:
For example: 例如:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.