2015年8月12日 星期三

8012 note

格式化物件:FormatConditions

with   範圍物件.FormatConditions
          .Delete
          .Add Type:=x,Operator:=y,Formula1:=z
          .Item(1).Interior.color=RGB(r,g,b)
end with


將物件設定給變數
Dim k as range
set k=Range("c2:e9")

Opertor
1.xlBetween   ->介於  兩個formula1  and formula2
2.xlEqual      等於
3.xlGreater   大於
4.xlGreaterEqual    大於等於
5.xlLess     小於
6.xlLessEqual    小於等於
7.xlNotBetween   不介於       兩個formula1  and formula2 
8.xlNotEqual    不等於

Type
1.xlCellValue            儲存格的值
2.xlExpresion       公式
3.xlBlanksCondition   空白
4.xlTextString   文字字串
5.xlTop10   前10名的值
6.xlIconSet  圖示集

1.Formula:公式化條件值
       formula1:=60,formila2:=80
2.Interior:指向背景

將不及格標示為紅色
 Dim k As FormatConditions
    Set k = Range("c2:e6").FormatConditions
 
    With k
        .Delete
        .Add Type:=xlCellValue, Operator:=xlLess, Formula1:=60
        .Item(1).Interior.Color = RGB(255, 0, 0)
    End With
移除格式化
   Dim k As FormatConditions
    Set k = Range("c2:e6").FormatConditions
 
    With k
        .Delete
        .Add Type:=xlCellValue, Operator:=xlLess, Formula1:=60
        .Item(1).Interior.Color = xlNone
    End With
標示空白資料
Private Sub CommandButton6_Click()
    Dim k As FormatConditions
    Set k = Range("c2:e6").FormatConditions
 
    With k
        .Delete
        .Add Type:=xlBlanksCondition
        .Item(1).Interior.Color = RGB(0, 255, 0)
    End With
End Sub

沒有留言:

張貼留言