【问题标题】:Excel checkboxes (VBA): Return a value if multiple boxes are checkedExcel 复选框 (VBA):如果选中多个框,则返回一个值
【发布时间】:2016-03-04 22:46:38
【问题描述】:

如果仅针对“每个项目限制”选中“是”,则适用表格 A。当勾选“每个位置限制”时,表格 B 将适用。但如果我同时检查两者,则适用表格 C。

我包含了用于每个复选框的电子表格和公式。 check9 是针对每个项目的限制,而 check10 是针对每个位置的限制。

Spreadsheet

  Private Sub check9_Click()
  If check9.Value = True Then
  Range("G24").Value = "Form A"
Else
  Range("G24").Value = " "

End If
End Sub

  Private Sub check10_Click()
  If check10.Value = True Then
  Range("G26").Value = "Form B"

Else
  Range("G26").Value = " "
End If
End Sub

【问题讨论】:

    标签: excel vba checkbox


    【解决方案1】:

    在决定表格时,您需要检查另一个复选框的状态。像这样的:

    Private Sub check9_Click()
        If check9.Value = True and check10.value = True Then
            Range("G24").Value = "Form C"
        ElseIf check9.Value = True and check10.Value = False Then
            Range("G24").Value = "Form B"
        ElseIf check9.Value = False and check10.Value = True Then
            Range("G24").Value = "Form A"
        End If
    End Sub
    
    Private Sub check10_Click()
        If check9.Value = True and check10.value = True Then
            Range("G24").Value = "Form C"
        ElseIf check9.Value = True and check10.Value = False Then
            Range("G24").Value = "Form B"
        ElseIf check9.Value = False and check10.Value = True Then
            Range("G24").Value = "Form A"
        End If
    End Sub
    

    【讨论】:

    • 您好,我希望表格 A、C 和 B 分别出现在单元格 G24、G25 和 G26 中。我调整了代码,如果没有检查,它将是空的。但是,如果我尝试同时单击两者,则会显示表格 C 和表格 A 或表格 B,这取决于我最初选中“是”的情况。有什么建议吗?
    • 所以选中 box1 清除 G25 和 G26 IF box2 未选中。 IF box2 勾选,box1 不勾选,THEN 清除 G24 和 G26。等等。您有 2 个事件(checknn_click 事件)和两个要评估的属性(checknn.value)。只需在点击事件中check the status of the other checkbox即可确定G24、25和26的值。
    【解决方案2】:

    在每次点击时调用此函数

    public function FormNeeded()    
        if check9.value=true and check10.value=false then
             range("g26").value="Form1"
        elseif check9.value=false and check10.value=true then
             range("g26").value="Form2"
        elseif check9.value=true and check10.value=true then
             range("g26").value="Form3"
        end if
    end function
    

    【讨论】:

      猜你喜欢
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 2018-03-20
      • 2021-12-24
      • 2022-11-27
      • 1970-01-01
      相关资源
      最近更新 更多