الحصول على قيم كل خانات الاختيار في Excel باستخدام VBA

StackOverflow https://stackoverflow.com/questions/1409744

  •  05-07-2019
  •  | 
  •  

سؤال

وأود أن أضيف العديد من مربعات الاختيار إلى ورقة التفوق programaticaly باستخدام التعليمات البرمجية التالية:

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

والآن أنا بحاجة رمز التي من شأنها أن تحليل من خلال جميع خانات الاختيار التي تكون موجودة في ورقة والحصول على قيمتها (صحيحة أو خاطئة)، وكذلك الخلية التي كانت موجودة. كيفية القيام بذلك؟

وشكرا ...

هل كانت مفيدة؟

المحلول

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

النهاية الفرعية

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top