|
よへです さん
こんにちは。
こんな感じでいいのかな?
Sub A()
'開始列位置 ← アルファベット
Const StrStartCol As String = "A"
'終了列位置 ← アルファベット
Const StrLastCol As String = "C"
'開始行位置 ← 数値
Const IntStartRow As Long = 1
'終了行位置 ← 数値
Const IntLastRow As Long = 100
'参照開始セルアドレス ← 数値
Const StrLookUpStart As String = "$DB$4"
'条件設定の際の色番号 ← 数値
Const IntColor As Long = 38
Dim IntStartCol As Long, IntLastCol As Long
Dim IntCol As Long, IntRow As Long, Cnt As Long
Dim RngLookup As Range
IntStartCol = Range(StrStartCol & "1").Column
IntLastCol = Range(StrLastCol & "1").Column
Cnt = 0
Set RngLookup = Range(StrLookUpStart)
Range(Cells(IntStartRow, IntStartCol), Cells(IntLastRow, IntLastCol)).FormatConditions.Delete
For IntCol = IntStartCol To IntLastCol
For IntRow = IntStartRow To IntLastRow
With Cells(IntRow, IntCol).FormatConditions
.Add Type:=xlExpression, Formula1:="=" & RngLookup.Address & "=1"
.Item(1).Interior.ColorIndex = IntColor
End With
Cnt = Cnt + 1
If Cnt = 2 Then
Cnt = 0
Set RngLookup = RngLookup.Offset(0, 1)
End If
Next
Set RngLookup = Range(StrLookUpStart).Offset(IntCol - IntStartCol + 1, 0)
Next
Set RngLookup = Nothing
End Sub
|
|