【发布时间】:2019-08-15 03:48:00
【问题描述】:
我有一个用户表单,在用户表单中有一个带有 4 个文本框的框架,我如何将这 4 个文本框的值传递到一个单元格中?用逗号或空格分隔。
我尝试在提交按钮中执行以下操作。
Dim t As MSForms.Control
For Each t In Me.Frame1.Controls
If TypeOf t Is MSForms.TextBox Then
If IsEmpty(stCode1Box) Then
Exit For
End If
If stCode1Box Is Nothing Then
'Cells(emptyRow, 15).Value = stCode1Box.Value
ElseIf Not IsEmpty(stCode1Box) Then
Cells(emptyRow, 15).Value = stCode1Box.Value
ElseIf stCode2Box Is Nothing Then
'Cells(emptyRow, 15).Value = stCode1Box.Value & ", " & stCode2Box.Value
ElseIf Not IsEmpty(stCode2Box) Then
Cells(emptyRow, 15).Value = stCode1Box.Value & ", " & stCode2Box.Value
ElseIf stCode3Box Is Nothing Then
'Cells(emptyRow, 15).Value = stCode1Box.Value & ", " & stCode2Box.Value & ", " & stCode3Box.Value
ElseIf Not IsEmpty(stCode3Box) Then
Cells(emptyRow, 15).Value = stCode1Box.Value & ", " & stCode2Box.Value & ", " & stCode3Box.Value
ElseIf stCode4Box Is Nothing Then
'Cells(emptyRow, 15).Value = stCode1Box.Value & ", " & stCode2Box.Value & ", " & stCode3Box.Value & ", " & stCode4Box.Value
ElseIf Not IsEmpty(stCode4Box) Then
Cells(emptyRow, 15).Value = stCode1Box.Value & ", " & stCode2Box.Value & ", " & stCode3Box.Value & ", " & stCode4Box.Value
End If
End If
Next t
结果会在该单元格上弹出,如果有多个文本框有值,则会用“,”逗号分隔。
【问题讨论】:
标签: vba textbox cell frame userform