簡體   English   中英

選中所有復選框以運行其他選定的框VBA Excel

[英]Select all check box to run other selected boxes VBA Excel

我正在嘗試有一個“全選”復選框,但是當所有復選框都選中時,它們不會起作用。

Sheet1中的字段不會導入或設置為Null 在自己的復選框上,將數據從Sheet1導入到位,但在主菜單下不起作用,請選擇所有checkbox1 on / off命令。

到目前為止,這是我的代碼:

Sub SelectAll_CHECK_BOX()
    Dim CB As CheckBox
    For Each CB In ActiveSheet.CheckBoxes
        If CB.Name <> "Check Box 1" Then
            CB.Value = ActiveSheet.CheckBoxes("Check Box 1").Value
        End If
    Next CB
End Sub

其他復選框具有以下代碼,其中每個復選框的范圍值和子名稱不同。

Sub CHECK_BOX_PRODUCT_NAME()
    Dim CB As CheckBox
        For Each CB In ActiveSheet.CheckBoxes
            If CB.Name <> ActiveSheet.CheckBoxes("Check Box 1").Name And CB.Value <> ActiveSheet.CheckBoxes("Check Box 1").Value And ActiveSheet.CheckBoxes("Check Box 1").Value <> 2 Then
                ActiveSheet.CheckBoxes("Check Box 1").Value = 2
                Exit For
            Else
                ActiveSheet.CheckBoxes("Check Box 1").Value = CB.Value
            End If
        Next CB
    Dim xChk As CheckBox
    Set xChk = ActiveSheet.CheckBoxes(Application.Caller)
    With xChk.TopLeftCell.Offset(0, 3)
        If xChk.Value = xlOff Then
            .Value = Null
        Else
            .Value = Sheets("Sheet1").Range("B9")
        End If
    End With
End Sub

這是問題的可視化: gif

您應該嘗試將Call CHECK_BOX_PRODUCT_NAME添加到第一個宏。 就在End Sub之前。

作為第一個宏,僅選中第二個復選框,而不運行第二個復選框的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM