[英]Access next item of a range from within a for loop (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
分兩步進行:
例如:
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.