Failed To Assign The IconSet Property In A FormatConditons

0

I am trying to automate the conditional format of a range and only accept three types of icons. The routine is in the click event of a button.

The code works as long as the value of the variable is less than or equal to three, variables xl3arrows, xl3arrowsgray, xl3flags. For higher values xl3signs, al3stars etc. The following error occurs:

Private Sub BtFormato_Click(sender As Object, e As EventArgs) Handles btFormato.Click
        Try
            Dim xlConditionValueNumber As Integer = 0
            Dim hoja As Excel.Worksheet = CType(Me.Application.ActiveSheet, Excel.Worksheet)
            Dim rango As Excel.Range = CType(hoja.Range("N5"), Excel.Range)
            rango.Select()
            Dim miRegion As Excel.Range = rango.CurrentRegion
            miRegion.Select()
            Dim cfCondicion As Excel.IconSetCondition = miRegion.FormatConditions.AddIconSetCondition()
            cfCondicion.ReverseOrder = True
            cfCondicion.ShowIconOnly = False
            cfCondicion.IconSet = cfCondicion.IconSet(Excel.XlIconSet.xl3Arrows)
            With cfCondicion.IconCriteria(2)
                .Type = xlConditionValueNumber
                .Value = 3
                .Operator = 7
            End With
            With cfCondicion.IconCriteria(3)
                .Type = xlConditionValueNumber
                .Value = 3
                .Operator = 5
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

When the value of the variable is greater than 3, the following error occurs:

System.Runtime.InteropServices.COMException HResult = 0x8002000B Message = The index is not valid. (Exception of HRESULT: 0x8002000B (DISP_E_BADINDEX)) Origin = Battery Tracking:

excel
vb.net
vsto
asked on Stack Overflow Aug 19, 2019 by Oscar Nogales • edited Aug 21, 2019 by Cindy Meister

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0