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
Set ws1 = Sheets("Master")
emptyRow = WorksheetFunction.CountA(range("A:A")) + 1
With ws1
.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
.Cells(emptyRow, 8).Value = cb.Name
End With
End If
'the master sheet needs to have a "Stakeholder" column with list of stakeholder the person belongs to
是Cb.Name - 我想要的名字複選框出現在一個單細胞,但現在它使取決於檢查箱子的數量額外行。因此,不是將6/8個複選框名稱放入1個單元格中,而是使用6行,每個名稱都不好。我如何將所有cb.names轉移到單個單元格中?這裏的問題如何將多個值添加到一個單細胞
對不起,如果代碼看起來不正確格式化 - 由於某種原因,它沒有顯示所有縮進...
嗨!所以我已經添加了代碼(並從它的外觀看起來就是我所需要的),但是當我因爲某種原因將其放入CommandButton1不再工作?我嘗試添加一個人但沒有任何反應..? – Doolie1106
所以其他工作表的工作,但沒有出現在主標籤,我似乎無法弄清楚爲什麼......? – Doolie1106
只是爲了保持代碼不變,我遺漏了原來的按鈕點擊。你必須做一個很小的調整 –