|
出来上がったようで何よりです。
インデントをしっかりつけることをお薦めします。
Sub fmcdtn()
Dim fc As FormatCondition
Dim gyou As Long
Dim retu As Long
Dim rng As Range
For i = 1 To Sheets.Count
Sheets(Sheets(i).Name).Activate
gyou = Cells(Rows.Count, 3).End(xlUp).Row
retu = Cells(1, Columns.Count).End(xlToLeft).Column
ActiveSheet.Cells.FormatConditions.Delete
Range("A1").Activate
Set rng = Range(Sheets(i).Cells(1, 1), Sheets(i).Cells(gyou, retu))
Set fc = rng.FormatConditions. _
Add(xlExpression, , "=COUNTIF(祝日データ,A$1)=1")
fc.Interior.Color = RGB(204, 255, 255)
gyou = 0
retu = 0
Next
End Sub
少し手を入れるとすると、こんな感じでしょうか。
できるだけ、シートやセルをSelectしないほうがよいかと思います。
Sub fmcdtn2()
Dim fc As FormatCondition
Dim gyou As Long
Dim retu As Long
Dim rng As Range
For i = 1 To Worksheets.Count
With Worksheets(i)
gyou = .Cells(.Rows.Count, 3).End(xlUp).Row
retu = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells.FormatConditions.Delete
Set rng = .Range(.Cells(1, 1), .Cells(gyou, retu))
Set fc = rng.FormatConditions. _
Add(xlExpression, , "=COUNTIF(祝日データ,A$1)=1")
fc.Interior.Color = RGB(204, 255, 255)
End With
Next
End Sub
|
|