【发布时间】:2014-01-28 18:16:22
【问题描述】:
Private Sub CommandButton1_Click()
Dim ctrl As control
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "CheckBox" Then
'Pass this CheckBox to the subroutine below:
TransferValues ctrl
End If
Next
End Sub
Sub TransferValues(cb As MSForms.CheckBox)
Dim ws As Worksheet
Dim emptyRow As Long
Dim ws1 As Worksheet
If cb Then
'Define the worksheet based on the CheckBox.Name property:
Set ws = Sheets(Left(cb.Name, 15))
emptyRow = WorksheetFunction.CountA(ws.range("A:A")) + 1
With ws
.Cells(emptyRow, 1).Value = surname.Value
.Cells(emptyRow, 2).Value = firstname.Value
.Cells(emptyRow, 3).Value = tod.Value
.Cells(emptyRow, 4).Value = program.Value
.Cells(emptyRow, 5).Value = email.Value
.Cells(emptyRow, 6).Value = officenumber.Value
.Cells(emptyRow, 7).Value = cellnumber.Value
End With
End If
'the master sheet needs to have a "Stakeholder" column with list of stakeholder the person belongs to
End Sub
根据检查的复选框,我只想将复选框的值编译到主选项卡和主选项卡中的一个单元格中。上面的代码根据该人所属的利益相关者传输每个文本框的值(这是通过复选框完成的)
例如,一个名叫 John Doe 的人属于 6/8 复选框,上面的代码将所有信息传输到 6/8 复选框表中。但我总是希望将信息填写在主选项卡中,并带有一个额外的列名称利益相关者,它将传输复选框的名称。当我尝试它时,它为每个复选框制作了单独的一行,而不是将其编译到一个单元格中。所以我用相同的信息制作了 6 个 John Doe,除了每个 John Doe 有不同的利益相关者他属于。
【问题讨论】: