|
我录制了一段宏,改编成一个函数
Function gs(km As String) As Boolean
Application.Goto Reference:=km
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
, Formula1:="=分数线!$F$6"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic
.ColorIndex = xlAutomatic
End With
Selection.FormatConditions(1).StopIfTrue = True
End Function
用于设置科目中大于等于多少分和格式,红色总分放置的是分数。这段代码可以运行,现在我改成下面的代码
Function gs(km As String, fs As String) As Boolean
Application.Goto Reference:=km
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
, Formula1:="fs"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic
.ColorIndex = xlAutomatic
End With
Selection.FormatConditions(1).StopIfTrue = True
End Function
因为要统计很多科目,我把放置分数和地方用一个变量代替,然后如下方法调用,为什么设置不了格式
Private Sub CommandButton1_Click()
Dim a(1 To 2) As String
Dim b As String
b = "=分数线!$F$6"
a(1) = "五数": a(2) = "六数"
Call gs(a(1), b)
Call gs(a(2), b)
End Sub
工作簿112.rar
(14.1 KB, 下载次数: 6)
|
|