我想从具有4个复选框选项的用户窗体中传递的值并将它们写入单个并置单元格。Excel VBA-将多个用户窗体复选框值写入单个单元格
当我选择我的窗体像这样:
我想将其保存到这样一个单元格:
我试着用以下完成这一代码(见下文),但它不适用于逗号等,如果只有第二,第三或第四项没有第一项选择。我确信有更好的方法,但我无法弄清楚或在网上找到答案。
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
亚历克斯,那看起来很棒。非常感谢。我会在这里尝试一下,让你知道它是怎么回事。我还没有学会如何这样做,并知道那里肯定有更好的办法。 – ReidC 2013-03-11 17:05:18
工作很好。我必须改变的是为分隔符添加空格以将其从“,”更改为“,” – ReidC 2013-03-11 17:30:28