VBAを使用してExcelのすべてのチェックボックスの値を取得する
質問
次のコードを使用して、プログラムでExcelシートに多くのチェックボックスを追加します。
With ActiveSheet.CheckBoxes.Add(rCell.Left, rCell.Top, rCell.Width, rCell.Height)
.Interior.ColorIndex = xlNone
.Caption = ""
End With
ここで、シートに存在するすべてのチェックボックスを解析し、それらの値(trueまたはfalse)とそれらが存在するセルを取得するコードが必要です。 これを行う方法
ありがとう...
解決
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
他のヒント
チェックボックスを追加したら、次のようにループできます:
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
サブの終了
所属していません StackOverflow