Excel 如果多个复选框为真,如何将文本添加到单元格的末尾?
我有一个表单,当我点击提交按钮时,它会将笔记输入一个单元格。作为注释的一部分,我有各种选项的复选框。我想做的是将复选框值添加到与注释相同的单元格的末尾。这就是我所拥有的:Excel 如果多个复选框为真,如何将文本添加到单元格的末尾?,excel,vba,Excel,Vba,我有一个表单,当我点击提交按钮时,它会将笔记输入一个单元格。作为注释的一部分,我有各种选项的复选框。我想做的是将复选框值添加到与注释相同的单元格的末尾。这就是我所拥有的: If Not IsEmpty(Notes.Text) Then ws.Range("N" & LastRow).Value = Notes.Text End If If TubeAdd.Value = True Then ws.Range("N" & LastRow).
If Not IsEmpty(Notes.Text) Then
ws.Range("N" & LastRow).Value = Notes.Text
End If
If TubeAdd.Value = True Then
ws.Range("N" & LastRow).Value = ActiveCell & ", Tubing"
End If
If Snowshoe.Value = True Then
ws.Range("N" & LastRow).Value = ActiveCell & ", Snowshoeing"
End If
If TubeExclusive.Value = True Then
ws.Range("N" & LastRow).Value = ActiveCell & ", Tubing"
End If
If Legacy.Value = True Then
ws.Range("N" & LastRow).Value = ActiveCell & ", Legacy Room"
End If
If NorthAxe.Value = True Then
ws.Range("N" & LastRow).Value = ActiveCell & ", North Axe Room"
End If
If MidMountainLodge.Value = True Then
ws.Range("N" & LastRow).Value = ActiveCell & ", MidMountain Lodge"
End If
If Catering.Value = True Then
ws.Range("N" & LastRow).Value = ActiveCell & ", Catering"
End If
我遇到的问题是,如果选中多个复选框,它只显示上次选中选项的“,****”。也就是说,如果选择了注释和配管与配管,我只会得到配管(“配管”)的结果。我需要所有数据显示在同一个单元格中
帮助?创建一个变量来存储字符串,并在所有if语句的末尾将该字符串粘贴到单元格中
dim notesval as string
If Not IsEmpty(Notes.Text) Then
notesval = Notes.Text
End If
if TubeAdd.Value = True Then
notesval = notesval & ", Tubing"
end if
'Finish the rest of the IFs
ws.Range("N" & LastRow).Value = notesval
通常情况下,您希望在代码中添加。查看示例数据和预期结果将非常有用
ws.Range(“N”和LastRow)。Value=ws.Range(“N”和LastRow)。Value&…
yaaaaaas非常感谢!!花了一秒钟,但我明白了!