iT邦幫忙

0

Excel VBA 尋找字串並標記顏色

  • 分享至 

  • xImage

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

以下為條件:
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

https://ithelp.ithome.com.tw/upload/images/20210211/20131103Ads1WSjHTr.jpg

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

1 個回答

0
rogeryao
iT邦超人 8 級 ‧ 2021-02-12 00:30:21
最佳解答
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

https://ithelp.ithome.com.tw/upload/images/20210212/200850214ghi6iU959.png

非常實用,感謝你的回答。

我要發表回答

立即登入回答