即効テクニック |
サンプルマクロは、アクティヴシートのA列で"OK"と記述されているものを上から順に調べ、1つおきに背景色を黄色にする処理を施します。フラグを使用したサンプルです。
Sub Sample()
Dim myRow As Long
Dim myFlag As Boolean
For myRow = 1 To Cells(Rows.Count, 1).End(xlUp).Row
With Cells(myRow, 1)
If .Value = "OK" Then
If myFlag Then .Interior.Color = RGB(255, 255, 0)
myFlag = Not myFlag
End If
End With
Next
End Sub