簡體   English   中英

根據一個單元格值更改多個單元格顏色

[英]changing multiple cell colors based on one cell value

如果單元格 A7 中的值是“鎖定”,我正在嘗試將單元格 A3 中的顏色更改為 A9。 到目前為止,我只能更改單元格 A7 中的值。 有人可以幫助我的代碼嗎?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("A3:A8")
For Each cell In myrange
If cell.Value Like "STBT" Then
cell.Interior.ColorIndex = 3
ElseIf cell.Value Like "Locked" Then
cell.Interior.ColorIndex = 4
Else: cell.Interior.ColorIndex = xlNone
End If
Next

End Sub

根據您的問題,代碼看起來像

Dim myrange As Range

Set myrange = Worksheets("Sheet1").Range("A3:A9") 

'Change the color in cells A3 to A9 if the value in cell A7 is Locked
If Range("A7").Value Like "Locked" Then 
    myrange.Cells.Interior.ColorIndex = 4
End If

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM