I am new to vb.net and VSTO and the documentation is not great for conditional formatting as I am modifying code from VBA to vb.net any ideas?
With customerYearRng
.FormatConditions.AddIconSetCondition()
'.IconSetCondition.IconSet.IconSets = "xl3Triangles"
'.FormatConditions(FormatConditions.Count).SetFirstPriority
'.FormatConditions(1)
'.FormatConditions.ReverseOrder = False
'.FormatConditions.ShowIconOnly = False
'.FormatConditions.IconSet.IconSets = "xl3Triangles"
'.FormatConditions(1).IconCriteria(2)
'.Type = xlConditionValueNumber
'.Value = 0
'.Operator = 7
'.FormatConditions(1).IconCriteria(3)
'.Type = xlConditionValueNumber
'.Value = 0
'.Operator = 5
End With
I'm not a VB.NET or VSTO programmer, but the small amount of Excel automation I've done from .NET seemed a pretty straightforward translation from a working VBA implementation.
Your code can be easier to deal with if you take advantage of the fact that AddIconSetCondition
returns the added condition, so you don't have to go looking for it in the range's FormatConditions
collection.
Working VBA (which I think is close to what you're wanting to set up in VB.NET) -
Sub Tester()
Dim rng As Range, isc As IconSetCondition
Set rng = Selection 'or whatever
Set isc = rng.FormatConditions.AddIconSetCondition()
isc.SetFirstPriority
isc.IconSet = rng.Parent.Parent.IconSets(xl3Triangles)
isc.ReverseOrder = False
isc.ShowIconOnly = False
With isc.IconCriteria(2)
.Type = xlConditionValueNumber
.Value = 0
.Operator = 7
End With
With isc.IconCriteria(3)
.Type = xlConditionValueNumber
.Value = 0
.Operator = 5
End With
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.