之前jimmytwo大大轉貼的程式碼:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Application.CutCopyMode = xlCopy Then Me.Paste
On Error Resume Next
[colorCell].FormatConditions.Delete
Target.Name = "colorCell"
With [colorCell].FormatConditions ' 設定格式化條件
.Delete
.Add xlExpression, , "TRUE" ' 條件(一)內公式為
.Item(1).Interior.ColorIndex = 36 ' .Item(1)等於FormatConditions(1)
.Item(1).Font.Bold = True
End With
End Sub
我想請問的是,上述程式執行後所選的儲存格的顏色可以改成其他的顏色(例如紅色)嗎?要如何改?謝謝!!!
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Application.CutCopyMode = xlCopy Then Me.Paste
On Error Resume Next
[colorCell].FormatConditions.Delete
Target.Name = "colorCell"
With [colorCell].FormatConditions ' 設定格式化條件
.Delete
.Add xlExpression, , "TRUE" ' 條件(一)內公式為
.Item(1).Interior.ColorIndex = 3 ' .Item(1)等於FormatConditions(1)
.Item(1).Font.Bold = True
End With
End Sub
除了ColorIndex屬性,也可以改用Interior物件的Color屬性。
Color屬性可以吃下列常數:vbBlack、vbBlue、vbCyan、vbGreen、vbMagenta、vbRed、vbWhite、vbYellow
如果對於上述顏色都不滿意,也用RGB()函數自己挑顏色。