下記で作動はするのですが、こういう感じのVBAをもっと簡潔に記載する方法はあるのでしょうか?
変数kが3ずつ増える、mが3ずつ増えるなど、規則性はあるので完結に書けそうなのですが、うまくいきません。
k=58 For i = 11 To 57 For j = 3 To 33 For m = 58 To 60 With ws1 If .Cells(i, j) Like "*ウ*" And .Cells(k, j).Value = "0" Then ws2.Cells(m, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*ケ*" And .Cells(k + 3, j).Value = "0" Then ws2.Cells(m + 3, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*ク*" And .Cells(k + 6, j).Value = "0" Then ws2.Cells(m + 6, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*市*" And .Cells(k + 9, j).Value = "0" Then ws2.Cells(m + 9, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*任*" And .Cells(k + 12, j).Value = "0" Then ws2.Cells(m + 12, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*ピ*" And .Cells(k + 15, j).Value = "0" Then ws2.Cells(m + 15, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*ジ*" And .Cells(k + 18, j).Value = "0" Then ws2.Cells(m + 18, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*本*" And .Cells(k + 21, j).Value = "0" Then ws2.Cells(m + 21, j).Interior.Color = RGB(255, 226, 121) End If If .Cells(i, j) Like "*武*" And .Cells(k + 24, j).Value = "0" Then ws2.Cells(m + 24, j).Interior.Color = RGB(255, 226, 121) End If End With Next m Next j Next i ' End Sub コード
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/10 10:01
2022/05/13 07:01