【发布时间】:2013-02-26 22:02:00
【问题描述】:
我正在尝试获取从具有 4 个复选框选项的用户窗体传递的值并将它们写入单个连接单元格。
当我像这样选择我的用户表单时:
我想将它保存到这样的单个单元格中:
我尝试使用以下代码(见下文)来完成此操作,但如果仅选择第 2、3 或第 4 项而不选择第一项,则逗号无法正常工作。我确信有更好的方法,但我无法弄清楚或在网上找到答案。
Private Sub cmdSave_Click()
Dim colors As String
If chkRed = True Then
colors = "Red"
Else
colors = colors
End If
If chkBlue = True Then
colors = colors & ", Blue"
Else
colors = colors
End If
If chkGreen = True Then
colors = colors & ", Green"
Else
colors = colors
End If
If chkYellow = True Then
colors = colors & ", Yellow"
Else
colors = colors
End If
With colorsSheet
.Cells(ActiveCell.Row, 1).Value = colors
End With
Unload Me
End Sub
【问题讨论】:
标签: excel vba checkbox concatenation userform