iT邦幫忙

0

Excel VBA 依照日期改變顏色

先在此感謝各位閱讀與幫忙

新增條件:
1.A3儲存格手動輸入日期
2.第四列依照A3儲存格日期,改變第五列至第十四列顏色

之前已完成條件,請參考連結:
1.A1到C1為變數,黃色
2.A2到C2為變數,綠色
3.數字變色限制在E5到E14之間
感謝rogeryao回覆解答
https://ithelp.ithome.com.tw/questions/10202206

https://ithelp.ithome.com.tw/upload/images/20210212/20131103arAwmF2wAA.jpg

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
rogeryao
iT邦超人 8 級 ‧ 2021-02-12 20:02:16
最佳解答
Private Sub CommandButton1_Click()
Dim u as Integer
u=0
For x= 3 To 5
    If (Cells(3, 1) = Cells(4, x)) Then
       u=x
     End If
Next x

If u>0 Then
  For i = 5 To 14
    For k = 1 To Range("A1").End(xlToRight).Column
      If (Cells(i, u) = Cells(1, k)) Then
        Cells(i, u).Interior.ColorIndex = 6
      ElseIf (Cells(i, u) = Cells(2, k)) Then
        Cells(i, u).Interior.ColorIndex = 4
      End If
    Next k
  Next i
End If

End Sub

實在太感謝了

我要發表回答

立即登入回答