先在此感謝各位閱讀與幫忙
以下為條件:
1.A1到C1為變數,黃色
2.A2到C2為變數,綠色
3.數字變色限制在E5到E14之間
有試寫但出現錯誤,請協助幫忙簡化以及修正,感謝。
Sub test()
For i = 1 To Range("A1").End(xlToRight).Row
Range("E5:E14").Find(DateValue(i)).Select
ActiveCell.Interior.ColorIndex = 6
Next
For i = 2 To Range("A2").End(xlToRight).Row
Range("E5:E14").Find(DateValue(i)).Select
ActiveCell.Interior.ColorIndex = 4
Next
End Sub
Private Sub CommandButton1_Click()
For i = 5 To 14
For k = 1 To Range("A1").End(xlToRight).Column
If (Cells(i, 5) = Cells(1, k)) Then
Cells(i, 5).Interior.ColorIndex = 6
ElseIf (Cells(i, 5) = Cells(2, k)) Then
Cells(i, 5).Interior.ColorIndex = 4
End If
Next k
Next i
End Sub