重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

【6/2終了】教えて!gooアプリ版

マクロの初心者です。2行毎のセルに色を付けたい時に、どのようにしたらできるのか、教えて頂けませんか。

If Cells(i, "Q") = 0 Then
Cells(i, "Q").Interior.ColorIndex = 3
End If
If Cells(i, "R") = 0 Then
Cells(i, "R").Interior.ColorIndex = 3
End If
If Cells(i, "S") = 0 Then
Cells(i, "S").Interior.ColorIndex = 3
End If
If Cells(i, "Q") >= 1 And Cells(i, "Q") < 20 Then
Cells(i, "Q").Interior.ColorIndex = 6 ' 6は  黄色
End If
If Cells(i, "R") >= 1 And Cells(i, "R") < 6 Then
Cells(i, "R").Interior.ColorIndex = 6 ' 6は  黄色 
End If
If Cells(i, "R") >= 6 And Cells(i, "R") < 10 Then
Cells(i, "R").Interior.ColorIndex = 34 '34は  淡い青色  
End If
If Cells(i, "S") >= 1 And Cells(i, "S") < 10 Then
Cells(i, "S").Interior.ColorIndex = 6 ' 6は  黄色   
End If
If Cells(i, "T") >= 1 And Cells(i, "T") <= 48 Then
Cells(i, "T").Interior.ColorIndex = 4 ' 4は  うぐいす色   
End If


If WorksheetFunction.CountBlank(Range("Q" & i & ":U" & i)) = 5 Then
Cells(i, "Q").Interior.ColorIndex = 46 '46は薄いオレンジ
End If
If WorksheetFunction.CountBlank(Range("Q" & i & ":U" & i)) = 5 Then
Cells(i, "R").Interior.ColorIndex = 46 '46は薄いオレンジ
End If
If WorksheetFunction.CountBlank(Range("Q" & i & ":U" & i)) = 5 Then
Cells(i, "S").Interior.ColorIndex = 46 '46は薄いオレンジ
End If
If WorksheetFunction.CountBlank(Range("Q" & i & ":U" & i)) = 5 Then
Cells(i, "T").Interior.ColorIndex = 46 '46は薄いオレンジ
End If
If WorksheetFunction.CountBlank(Range("Q" & i & ":U" & i)) = 5 Then
Cells(i, "U").Interior.ColorIndex = 46 '46は薄いオレンジ
End If

A 回答 (1件)

1行目から10行目までを2行間隔をあけて色を塗りたい場合、下記のようにすればできます。



Sub Sample()
Dim i As Long

For i = 1 to 10 Step 3

ここに上記のマクロを入れる

Next

End Sub

★行間隔はFor文のStepのところで間隔をあけたい数+1を指定します。
    • good
    • 1
この回答へのお礼

なるほど、初心者です。お教え頂きありがとうございました。

お礼日時:2018/02/13 18:00

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!