我正在使用VBA代码放置条件格式以覆盖大表中的值,每个单元格使用2个公式来确定要使用3个符号中的哪一个。我需要根据列来检查具有不同单元格的每个单元格的值,因此就我理解不足而言,我必须将条件格式设置规则分别放在每个单元格上,以确保每个单元格中的公式正确。这是因为条件格式不能使用相对地址,您必须给它每个单元格的确切地址...对吗?
大量的条件格式实例在很大程度上减慢了我的计算机的速度。
是否可以在不使用条件格式的情况下将条件格式使用的符号放置到单元格中?
也许有点像图像,但是保留了下面的单元格值,这可以使用条件格式完成。
在下面,我给出了用于放置条件格式的代码。很感谢任何形式的帮助!!
Dim AIs As Range
Dim rng As Range
Dim cl As Range
Set AIs = ActiveSheet.Range("Table")
For Each cl In AIs.Columns
For Each rng In cl.Cells
rng.FormatConditions.AddIconSetCondition
rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
With rng.FormatConditions(1)
.ReverseOrder = False
.ShowIconOnly = True
.IconSet = ActiveWorkbook.IconSets(xl3Symbols2)
End With
With rng.FormatConditions(1).IconCriteria(1)
.Icon = xlIconYellowExclamationSymbol
End With
With rng.FormatConditions(1).IconCriteria(2)
.Icon = xlIconRedCross
.Type = xlConditionValueFormula
.Value = "=IF(VALUE(LEFT(" & rng.Parent.Cells(5, rng.Column).Address & _
";1)=0;1;6)"
.Operator = 7
End With
With rng.FormatConditions(1).IconCriteria(3)
.Icon = xlIconGreenCheck
.Type = xlConditionValueFormula
.Value = "=IF(VALUE(LEFT(" & rng.Address & ";1))<=VALUE(LEFT(" & _
rng.Parent.Cells(5, rng.Column).Address & ";1));1;6)"
.Operator = 7
End With
Next rng
Next cl
将形状直接添加到单元格:
Dim cLeft As Single
Dim cTop As Single
cLeft = rng.Left
cTop = rng.Top
with AIs.Shapes.AddShape(msoShapeOval, cLeft, cTop, 12, 12)
.ForeColor.RGB = RGB(255, 0, 0)
'Other properties can be found at
'http://msdn.microsoft.com/en-us/library/office/bb251480%28v=office.12%29.aspx
end with
您可能需要调整cTop和cLeft以及宽度/高度以根据需要定位圆
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句