Pergunta

eu adicionar muitas caixas de seleção para a folha de excel programaticaly usando o seguinte código:

With ActiveSheet.CheckBoxes.Add(rCell.Left, rCell.Top, rCell.Width, rCell.Height)
        .Interior.ColorIndex = xlNone
        .Caption = ""
End With

Agora eu preciso de um código que iria analisar através de todas as caixas de verificação que estão presentes na folha e obter o seu valor (verdadeiro ou falso) e também a célula em que eles estão presentes. Como fazer isso?

Obrigado ...

Foi útil?

Solução

Sub Add_CheckBoxes()

With ActiveSheet.CheckBoxes.Add(ActiveCell.Left, ActiveCell.Top, ActiveCell.Width, ActiveCell.Height)
    .Interior.ColorIndex = xlNone
    .Caption = ""
End With

For Each chk In ActiveSheet.CheckBoxes
    If chk Then MsgBox "Checked"
Next
End Sub

Outras dicas

Depois de adicionar as caixas de seleção que você pode percorrer-los como este:

Sub Checkbox_Test()

Dim chk As CheckBox
Dim cell As Range

For Each chk In ActiveSheet.CheckBoxes
    If chk.Value = Checked Then        '1 is true, but the constant
        Set cell = chk.TopLeftCell     ' "Checked" avoids "magic numbers".

        'do whatever with cell
        MsgBox cell.Address
    End If
Next chk

End Sub

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top