Saturday, October 4, 2008

Color Band 的用法


试一试以下的 vba:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)Dim iColor As Integer

On Error Resume
NextiColor = Target.Interior.ColorIndex

If iColor <0

Then
iColor = 6 [可更改-> 0 至55]
Else
iColor = iColor + 2 [可变动]
End If

If iColor = Target.Font.ColorIndex Then iColor = iColor + 1
Cells.FormatConditions.Delete

With Range("A" &Target.Row, Target.Address) 'Rows(Target.Row)
.FormatConditions.Add Type:=2, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = iColor
.FormatConditions(1).Font.Bold = TrueEnd With


With Range(Target.Offset(1 - Target.Row, 0).Address & ":" & _
Target.Offset(-1, 0).Address) 'Rows(Target.Row)
.FormatConditions.Add Type:=2, Formula1:="FALSE"
.FormatConditions(1).Interior.ColorIndex = 0

End With

End Sub