Excel 中的互斥复选框(切换)

发布于 2024-09-06 02:11:04 字数 202 浏览 3 评论 0原文

我的电子表格包含表单工具栏中的 50 多个复选框。在某些情况下,您只能选中一组中的 1 个复选框,即选中从复选框 1 到复选框 5 中的一个复选框。

如果可能的话,我尝试在不使用任何代码的情况下实现这一目标。选项按钮不是首选,因为我想要统一的电子表格。

如何将 checkbox1 到 checkbox5 分组,以便它们在一个组中互斥。

谢谢

I have spreadsheet with 50+ checkboxes from the forms toolbar. In a few instances you can only check 1 checkbox from a group i.e you check one checkbox from checkbox 1 to checkbox 5.

I'm trying to achieve this without any code if possible. Option button is not preferred since I want an uniformed spreadsheet.

How can you group the checkbox1 to checkbox5 so that they become mutually exclusive for a group.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久伴你 2024-09-13 02:11:04

您可能需要使用单选按钮,组之间可能有分隔符,因为这也向最终用户表明这些字段是互斥的。

根据定义,单选按钮在组内是互斥的。

请记住,在应该使用单选框的地方使用复选框会让最终用户感到困惑,因为他们想知道为什么该复选框突然停用,而使用单选按钮时,混淆因素不存在。

You might want to use a radio button, with possibly a separator between the groups, as this also signifies to the end-user that those fields are mutually exclusive.

A radio button, by definition, is Mutually Exclusive within a group.

Remember that using checkboxes in places where you should be using radio boxes will be confusing your end-users, as they wonder why that checkbox is suddenly de-activated, while when using radio buttons the confusion factor is non-existant.

漆黑的白昼 2024-09-13 02:11:04

如果您无法使用选项按钮,请尝试此代码

Private Sub CheckBox1_Change()

    With Me.CheckBox1
        If .Value Then ClearGroup .GroupName, .Name
    End With

End Sub

Private Sub CheckBox2_Change()

    With Me.CheckBox2
        If .Value Then ClearGroup .GroupName, .Name
    End With

End Sub

Private Sub CheckBox3_Change()

    With Me.CheckBox3
        If .Value Then ClearGroup .GroupName, .Name
    End With

End Sub

Private Sub ClearGroup(sGroup As String, sName As String)

    Dim ole As OLEObject

    For Each ole In Me.OLEObjects
        If TypeName(ole.Object) = "CheckBox" Then
            If ole.Object.GroupName = sGroup And ole.Name <> sName Then
                ole.Object.Value = False
            End If
        End If
    Next ole

End Sub

If you can't use Option Buttons, try this code

Private Sub CheckBox1_Change()

    With Me.CheckBox1
        If .Value Then ClearGroup .GroupName, .Name
    End With

End Sub

Private Sub CheckBox2_Change()

    With Me.CheckBox2
        If .Value Then ClearGroup .GroupName, .Name
    End With

End Sub

Private Sub CheckBox3_Change()

    With Me.CheckBox3
        If .Value Then ClearGroup .GroupName, .Name
    End With

End Sub

Private Sub ClearGroup(sGroup As String, sName As String)

    Dim ole As OLEObject

    For Each ole In Me.OLEObjects
        If TypeName(ole.Object) = "CheckBox" Then
            If ole.Object.GroupName = sGroup And ole.Name <> sName Then
                ole.Object.Value = False
            End If
        End If
    Next ole

End Sub
桜花祭 2024-09-13 02:11:04

为什么您认为选项(单选)按钮是互斥的?我有两个人在一组。当我点击其中一个时,另一个就会打开。并且没有办法取消选择它们。它们最初按预期工作,但是当我为不相关的控件创建第二个组并使用带有两个选项按钮的不同链接框时,奇怪的行为开始了。到目前为止,我能做的最好的事情就是为每个控件组合和无组设置一个单独的单选按钮。

Why do you think option (radio) buttons are mutually exclusive? I have two of them in a group. When I click one of them, the other turns on. And there is no way to deselect them. They initially worked as intended, but when I created a second group for an unrelated control with a different link box with two more option buttons, the bizarre behavior began. So far, the best I can do is a separate radio button for each COMBINATION of controls and NO group.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文