填充用户表单checkbox和可选button的数据

我正在创build一个用户表单,我希望能够填充数据选项卡中的值以及默认值到某些值。 我想我有文本框和combobox下来,但不能find使用多个可选button生成数据到一个单元的信息取决于select。 示例草稿

从这个例子来看,我的标准是“二级保险”,我怎样才能把它们全部联系起来,让单元格b1填充选定的选项? 我完全猜测,但我认为checkbox是更简单一点,如果选中,则为true,如果未选中,则为false。 我到目前为止只是一个代码,我遇到填写单元格的指定文本/combobox的值,只是要重复每个列我需要设置一个标准。

Private Sub CommandButton1_Click() Dim LastRow As Long, ws As Worksheet Set ws = Sheets("Sheet1") LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row ws.Range("A" & LastRow).Value = TextBox1.Text 'Adds the TextBox1 into Col A & Last Blank Row Me.Hide End Sub 

combobox列表

 Private Sub UserForm_Initialize() ComboBox1.Value = ("N/A") ComboBox1.List = Split("N/A Yes No") End Sub 

请让我知道,如果我缺乏信息或如何附加我的testing工作表,希望你能看到图片(我不能在我的工作服务器上)。 预先感谢任何和所有的教育。

如果选项button的标题与你想要的单元格文字相同,那么类似这样的东西可能就是你想要存储的东西:

 Private Sub CommandButton1_Click() Dim LastRow As Range With Sheets("Sheet1") Set LastRow = .Rows(.Cells(Rows.Count, 1).End(xlUp).Row + 1).Cells If OptionButton1 Then LastRow(2).Value2 = Me.OptionButton1.Caption ElseIf Me.OptionButton2 Then LastRow(2).Value2 = Me.OptionButton2.Caption Else LastRow(2).Value2 = Me.OptionButton3.Caption End If End With End Sub 

这会将所需的单元格设置为您所select的选项button的标题的值。

要将数据加载回用户表单,可以使用如下所示的内容:

 Sub Load_in(Row_To_Load As Long) Dim MyRow As Range With Sheets("Sheet1") Set MyRow = .Rows(Row_To_Load).Cells If MyRow(2).Value2 = OptionButton1.Caption Then OptionButton1.Value = True ElseIf MyRow(2).Value2 = OptionButton2.Caption Then OptionButton2.Value = True Else OptionButton3.Value = True End If End With End Sub 

为此,我假定名字没有改变。 此外,如果没有select,第三个选项(N / A)将被使用。 加载它也是一样的。 如果你不想这样做,只需将Else部分更改为ElseIf ,使其看起来像前两个选项。