【问题标题】:VBA to Include Check Boxes into Userform that gets checked/unchecked depending on table valueVBA 将复选框包含在用户表单中,根据表值选中/取消选中
【发布时间】:2018-05-02 16:42:29
【问题描述】:

请求:在我的用户表单中包含一个复选框,根据表格列中的 True/False 值选中/取消选中

当前状态

我有一个用户表单,用于在表格中添加编辑或删除条目。 具体来说,编辑工作的方式是,我有一个与 A 列中的邮件地址相对应的组合框和表格每一列的文本框。

当您在组合框中选择邮件地址时,用户表单的文本框将使用该行中的数据填充。

例如,我想添加一个 复选框,上面写着 "married" 并对应于表中具有“True”或“False”的列价值观。现在应该根据相应列中的值自动选中/取消选中此复选框。

我的代码:

Private Sub c_01_Change()

' c_01 is the combo box
   With c_01
   ' B_02 is the delete button
   ' B_03 is the save button
        B_02.Visible = .ListIndex > -1
        B_03.Visible = True
        If .ListIndex = -1 Then Exit Sub

        ' T_0X are the text boxes
        For j = 0 To UBound(.List, 2)
            Me("T_" & Format(j, "00")).Text = .Column(j)
            Me("T_" & Format(j, "00")).Locked = False
            If j > 2 Then Me("T_" & Format(j, "00")).Text = Format(.Column(j), "0.00")
        Next
    End With
End Sub

Private Sub T_00_Change()
    M_text 0
    B_02.Visible = T_00.Text <> ""
End Sub
Private Sub T_01_Change()
    M_text 1
End Sub
Private Sub T_02_Change()
    M_text 2
End Sub
Private Sub T_03_Change()
    M_text 3
End Sub
Private Sub T_04_Change()
    M_text 4
End Sub
Sub M_text(y)
    If c_01.ListIndex > -1 Then c_01.Column(y) = Me("T_" & Format(y, "00")).Text
End Sub

【问题讨论】:

    标签: vba excel


    【解决方案1】:
    1. 添加一个复选框。
    2. 然后检查单元格中的值。在我的例子中是Cells(1,1):
    3. 这样写:

    CheckBox1.Value = CBool(Cells(1, 1))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-14
      • 2018-06-06
      • 2013-11-04
      • 2020-03-13
      • 1970-01-01
      • 2020-06-18
      • 2021-07-28
      相关资源
      最近更新 更多