Excel复选框(VBA):如果选中多个复选框,则返回一个值

Excel复选框(VBA):如果选中多个复选框,则返回一个值,excel,vba,checkbox,Excel,Vba,Checkbox,如果仅针对“每个项目限额”勾选“是”,则表格A适用。当勾选“每个位置限制”时,表格B适用。但如果我同时勾选两者,则表格C适用 我包括了电子表格和用于每个复选框的公式。检查9表示每个项目的限制,而检查10表示每个位置的限制 每次单击都取消此功能 public function FormNeeded() if check9.value=true and check10.value=false then range("g26").value="Form1"

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

我包括了电子表格和用于每个复选框的公式。检查9表示每个项目的限制,而检查10表示每个位置的限制


每次单击都取消此功能

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

在决定表单时,需要检查其他复选框的状态。大概是这样的:

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,具体取决于我最初选择的“是”。有什么建议吗?如果未选中框2,则选中框1将清除G25和G26<代码>如果选中了框2而未选中框1,则清除G24和G26。等等。您有两个事件(checknn_click events)和两个要评估的属性(checknn.value)。只需检查单击事件中其他复选框的状态即可确定G24、25和26的值。
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