我遇到了雙循環交替格式化我的行的函數的問題。嵌套如果語句轉換爲雙循環
我知道我可以通過條件格式對範圍腳本執行此操作,但是由於我學習越來越多地使用VBA,我認爲嘗試使用雙循環會很好。
我沒能進一步得到。
Sub AlternateRowColor2()
Dim lastRow As Long
lastRow = Range("A1").End(xlDown).Row
For Each Cell In Range("A1:A" & lastRow)
If Cell.Row Mod 2 = 1 Then
Cell.Interior.ColorIndex = 43
remove
End If
Next Cell
End Sub
我可以去定義循環,但迷失在for
功能下一
Sub AlternateRowColors()
Dim I As Integer
Dim P As Integer
Dim lastRow As Long
For I = 1 To 2
For P = 1 To 1
lastRow = Range(P).End(xlDown).Row
For Each Column In Range(I, lastRow)
我可以繼續使用這個代碼的每個單元格嗎? –
@AsimAhmed號由於您沒有使用For Each循環。您需要使用嵌套for循環中的索引來獲取特定的範圍。 – Adjit