iT邦幫忙

0

儲存格內容字串比對問題

以下為VBA條件:
1.儲存格內容為不固定亂數
2.儲存格內容,亂數只要前三碼相符即變色
3.變色儲存格,即使與下一格不一樣,也保持變色
https://ithelp.ithome.com.tw/upload/images/20201101/20131103xWTTULG5dN.jpg

感謝回答者。

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

1 個回答

1
海綿寶寶
iT邦大神 1 級 ‧ 2020-11-01 09:11:18
最佳解答

從 A1 開始往下逐列判斷直到儲存格為空值為止

Sub MarkColor()
    Dim sKey As String
    Range("A1").Select
    Do While ActiveCell.Value <> ""
        If sKey = Left(ActiveCell.Value, 3) Then
            ActiveCell.Interior.ColorIndex = 6
            ActiveCell.Interior.Pattern = xlSolid
            ActiveCell.Offset(-1, 0).Interior.ColorIndex = 6
            ActiveCell.Offset(-1, 0).Interior.Pattern = xlSolid
        End If
        sKey = Left(ActiveCell.Value, 3)
        ActiveCell.Offset(1, 0).Select
    Loop
End Sub

謝謝你的回答,讚。

我要發表回答

立即登入回答