我使用 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 以及宽度/高度以根据需要调整圆的位置
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)