Tạo một module có nội dung:
Sub ConditionalFormattingExample()
'Khai bao vung dinh dang co dieu kien
Dim MyRange As Range
Set MyRange = Range("A1:B10")
'Xoa dinh dang co dieu kien hien co
MyRange.FormatConditions.Delete
'Ap dung dinh dang co dieu kien
MyRange.FormatConditions.Add Type:=xlExpression, Formula1:="=COUNTA(A1)>0"
MyRange.FormatConditions(MyRange.FormatConditions.Count).SetFirstPriority
With MyRange.FormatConditions(1).Borders()
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Thay A1:B10 bằng vùng muốn tự động kẻ khung cho ô có dữ liệu.
No comments :