misser wrote:
1.考試登記,格子不到60分的,用顏色標註:
用set會比較好寫,增加、減少條件也比較直覺,請參考
'工作表2、a1~a10、大於0、小於0、粗體字

Sub SetFormatCondition()
Dim Crange As Range, C1 As FormatCondition, C2 As FormatCondition ' Cn As FormatCondition
'範圍
Set Crange = Sheets("工作表2").Range("a1", Sheets("工作表2").Range("a1").End(xlDown))
Crange.FormatConditions.Delete
Crange.Font.Bold = True
'條件1
Set C1 = Crange.FormatConditions.Add(xlCellValue, xlGreater, "=0")
C1.Font.Color = vbRed
'條件2
Set C2 = Crange.FormatConditions.Add(xlCellValue, xlLess, "=0")
C2.Font.Color = -11489280
'條件n...
'...
'...
Set Crange = Nothing
End Sub
misser wrote:
第2個例子:滑鼠移到該列,會自動顏色標註(我同事說很好用,尤其是資料欄位多時)
程式碼:(有2處要加喔,效果才會出來) 1.模組內 2.工作表內。
改這樣寫,就只需要放一個位置
'程式碼需放到工作表內(非模組)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Selection.Worksheet.Cells.FormatConditions.Delete
Rows(ActiveCell.Row).FormatConditions.Add xlExpression, , "TRUE"
Rows(ActiveCell.Row).FormatConditions(1).Interior.ThemeColor = 5
'Columns(ActiveCell.Column).FormatConditions.Add xlExpression, , "TRUE"
'Columns(ActiveCell.Column).FormatConditions(2).Interior.ThemeColor = 6
'.Interior.ThemeColor = 5 '.Interior.Color = vbGreen '.Interior.Color = RGB(200, 80, 100) '.Interior.ColorIndex = 8
End Sub