首页 文章

VBA将复选框包含到Userform中,根据表值进行检查/取消选中

提问于
浏览
0

The request: Include a check box in my userform that gets checked/unchecked depending on True/False value in column of table

Current state

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

在组合框中选择邮件地址时,用户表单的文本框将填入该行的数据 .

enter image description here

对于该示例,我想添加一个 check box ,其中包含 "married" ,并且对应于表中具有"True"或"False"值的列 . 现在应根据相应列中的值自动选中/取消选中此复选框 .

My code:

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

1 回答

  • 0
    • 添加一个复选框 .

    • 然后检查单元格中的值 . 在我的例子中它是 Cells(1,1)

    • 写这个:

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

相关问题