| 条件に一致したセルに対して、1つおきに処理を施す(フラグを使用) |
|---|
サンプルマクロは、アクティヴシートの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
|
| Excel95/97/2000 |