将用户来自复选框的内容连接到单元格,并使用分隔符。

huangapple go评论70阅读模式
英文:

Userfrom Checkbox concatenate to cell with separators

问题

I have created userform to enter data to excel sheet. The userform contains textbox, combobox and checkbox. I have separated the checkbox with two different group but not in frame. 2 groups with 5 checkbox each group. Group name i have given in checkbox properties. The value of the checkbox is written is Caption properties.

我已创建用户窗体以输入数据到Excel工作表。用户窗体包含文本框、组合框和复选框。我将复选框分成两个不同的组,但没有放在框架中。每个组有5个复选框。组名在复选框属性中指定。复选框的值写在标题属性中。

I have given this code to enter data i desired.

我已提供以下代码以输入所需的数据。

Dim selectedOptions1 As String
Dim selectedOptions2 As String
If ColSamp.Value = True Then
selectedOptions1 = ColSamp.Caption
End If
If Dummy.Value = True Then
If selectedOptions1 <> "" Then
selectedOptions1 = selectedOptions1 & " & "
End If
selectedOptions1 = selectedOptions1 & Dummy.Caption
End If
If gmg.Value = True Then
If selectedOptions1 <> "" Then
selectedOptions1 = selectedOptions1 & " & "
End If
selectedOptions1 = selectedOptions1 & gmg.Caption
End If
If LsrPrf.Value = True Then
If selectedOptions1 <> "" Then
selectedOptions1 = selectedOptions1 & " & "
End If
selectedOptions1 = selectedOptions1 & LsrPrf.Caption
If SizSamp.Value = True Then
If selectedOptions1 <> "" Then
selectedOptions1 = selectedOptions1 & " & "
End If
selectedOptions1 = selectedOptions1 & SizSamp.Caption
End If
End If
If Emboss.Value = True Then
selectedOptions2 = Emboss.Caption
End If
If Deboss.Value = True Then
If selectedOptions2 <> "" Then
selectedOptions2 = selectedOptions2 & " & "
End If
selectedOptions2 = selectedOptions2 & Deboss.Caption
End If
If DieCuting.Value = True Then
If selectedOptions2 <> "" Then
selectedOptions2 = selectedOptions2 & " & "
End If
selectedOptions2 = selectedOptions2 & DieCuting.Caption
End If
If WindPast.Value = True Then
If selectedOptions2 <> "" Then
selectedOptions2 = selectedOptions2 & " & "
End If
selectedOptions2 = selectedOptions2 & WindPast.Caption
If FoldPaste.Value = True Then
If selectedOptions2 <> "" Then
selectedOptions2 = selectedOptions2 & " & "
End If
selectedOptions2 = selectedOptions2 & FoldPaste.Caption
End If
End If

it is working if i checked all the check box if i'm checked one box between the value is not combining after that. What i'm doing wrong in this.

如果我勾选了所有复选框,它可以工作,但如果我只勾选了一个复选框,之后的值就不会组合起来。我在这里做错了什么?

英文:

I have created userform to enter data to excel sheet. The userform contains textbox, combobox and checkbox. I have separated the checkbox with two different group but not in frame. 2 groups with 5 checkbox each group. Group name i have given in checkbox properties. The value of the checkbox is written is Caption properties.

I have given this code to enter data i desired.

Dim selectedOptions1 As String
Dim selectedOptions2 As String
  If ColSamp.Value = True Then
    selectedOptions1 = ColSamp.Caption
     End If
     If Dummy.Value = True Then
        If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; Dummy.Caption
End If
If gmg.Value = True Then
    If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; gmg.Caption
End If
If LsrPrf.Value = True Then
    If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; LsrPrf.Caption
If SizSamp.Value = True Then
    If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; SizSamp.Caption
End If
End If
If Emboss.Value = True Then
    selectedOptions2 = Emboss.Caption
     End If
If Deboss.Value = True Then
    If selectedOptions2 &lt;&gt; &quot;&quot; Then
        selectedOptions2 = selectedOptions2 &amp; &quot; &amp; &quot;
    End If
    selectedOptions2 = selectedOptions2 &amp; Deboss.Caption
End If
If DieCuting.Value = True Then
    If selectedOptions2 &lt;&gt; &quot;&quot; Then
        selectedOptions2 = selectedOptions2 &amp; &quot; &amp; &quot;
    End If
    selectedOptions2 = selectedOptions2 &amp; DieCuting.Caption
End If
If WindPast.Value = True Then
    If selectedOptions2 &lt;&gt; &quot;&quot; Then
        selectedOptions2 = selectedOptions2 &amp; &quot; &amp; &quot;
    End If
    selectedOptions2 = selectedOptions2 &amp; WindPast.Caption
If FoldPaste.Value = True Then
    If selectedOptions2 &lt;&gt; &quot;&quot; Then
        selectedOptions2 = selectedOptions2 &amp; &quot; &amp; &quot;
    End If
    selectedOptions2 = selectedOptions2 &amp; FoldPaste.Caption
End If
End If

it is working if i checked all the check box if i'm checked one box between the value is not combining after that. What i'm doing wrong in this.

答案1

得分: 0

只要 SizSamp 和 FoldPaste 被选中,就会发生这种情况。

End If
If SizSamp.Value = True Then
    If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; SizSamp.Caption
End If
End If

更改为

End If
If SizSamp.Value = True Then
    If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; SizSamp.Caption
End If

并在 FoldPaste 处执行相同操作。

英文:

It can happen if SizSamp and FoldPaste are checked.

If SizSamp.Value = True Then
    If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; SizSamp.Caption
End If
End If

Change

End If
If SizSamp.Value = True Then
    If selectedOptions1 &lt;&gt; &quot;&quot; Then
        selectedOptions1 = selectedOptions1 &amp; &quot; &amp; &quot;
    End If
    selectedOptions1 = selectedOptions1 &amp; SizSamp.Caption
End If

and do the same at FoldPaste.

huangapple
  • 本文由 发表于 2023年5月7日 12:49:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192237.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定