如何在excel中加入 单选框

如何在excel中加入 单选框,第1张

具体 *** 作步骤如下:

一、首先,打开excel表格。新建空白工作簿。

二、在菜单栏中点击文件。

三、然后点击选项。

四、点击“自定义功能区”,选中“开发工具”复选框,然后单击“确定”。

五、在菜单栏中点击开发工具,插入,选项按钮。

六、一次只能添加一个选项按钮。 若要加快速度,请在添加第一个控件后右键单击它,然后选择“复制”,“粘贴”。

七、若要编辑或删除控件的默认文本,请单击该控件,然后根据需要更新文本。

因为checkbox默认的 *** 作是点一次选中,点两次取消选中,所以要修改代码,加一个布尔变量标记

修改后的代码如下:

Dim flag As Boolean

Private Sub CheckBox1_Click()

    flag = False

    If flag = False Then

        CheckBox1.Value = 1

        CheckBox2.Value = 0

        CheckBox3.Value = 0

        CheckBox4.Value = 0

        flag = True

    End If

End Sub

Private Sub CheckBox2_Click()

    If flag = True Then

        CheckBox1.Value = 0

        CheckBox2.Value = 1

        CheckBox3.Value = 0

        CheckBox4.Value = 0

        flag = False

    End If

End Sub

Private Sub CheckBox3_Click()

    If flag = False Then

        CheckBox1.Value = 0

        CheckBox2.Value = 0

        CheckBox3.Value = 1

        CheckBox4.Value = 0

        flag = True

    End If

End Sub

Private Sub CheckBox4_Click()

    If flag = True Then

        CheckBox1.Value = 0

        CheckBox2.Value = 0

        CheckBox3.Value = 0

        CheckBox4.Value = 1

        flag = False

    End If

End Sub

对于多选类型的“组合框/列表框”,其内部的单选框个数等于列表项个数:

即:

ComboBox1.ListCount

ListBox1.ListCount

对于用Frame对象集合的单选/多选框,可以用Controls.Count属性获得:

即:

Frame1.Controls.Count


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/bake/11768038.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存