mardi 23 janvier 2018

Selecting all check boxes in a range works only after worksheet's been open for a while

I'm using this macro to select a column range of checkboxes if a particular box is checked, and to uncheck all remaining checkboxes.

Sub SelectAll_Click_Formale_Denkstörungen()

    Dim CB As CheckBox
    Dim Nicht_Vorhanden As Range
    Dim leichtgradige As Range
    Dim mittelgradige As Range
    Dim schwergradige As Range
    Dim keineAussage As Range
    Set Nicht_Vorhanden = Hoja2.Range("E26:E38")
    Set leichtgradige = Hoja2.Range("F26:F38")
    Set mittelgradige = Hoja2.Range("G26:G38")
    Set schwergradige = Hoja2.Range("H26:H38")
    Set keineAussage = Hoja2.Range("I26:I38")

        For Each CB In Hoja2.CheckBoxes
            If Not Intersect(CB.TopLeftCell, Nicht_Vorhanden) Is Nothing Then
            CB.Value = Hoja2.CheckBoxes("Check Box 513").Value
            End If
            If Not Intersect(CB.TopLeftCell, leichtgradige) Is Nothing Then
            CB.Value = -4146
            End If
            If Not Intersect(CB.TopLeftCell, mittelgradige) Is Nothing Then
            CB.Value = -4146
            End If
            If Not Intersect(CB.TopLeftCell, schwergradige) Is Nothing Then
            CB.Value = -4146
            End If
            If Not Intersect(CB.TopLeftCell, keineAussage) Is Nothing Then
            CB.Value = -4146
            End If
        Next CB
End Sub

I'm using this very same macro in several instances of the worksheet and most of them work fine, but for a few, it leaves some of the checkboxes it's supposed to check unchecked, but it will work properly after the worksheet has been open for a few minutes. Does anyone know why this may be happening?




Aucun commentaire:

Enregistrer un commentaire