【发布时间】:2021-09-28 07:15:15
【问题描述】:
我有一个用户窗体,它填充了一个多选列表框(基于隐藏工作表中的逗号分隔单元格)。
如果用户从列表框中选择了单个项目,我希望根据他们的选择显示该项目的特定注释。
如果他们选择了 MULTIPLE,我希望备注将他们刚刚选择的项目的备注添加到现有的备注中,而不复制最初选择的项目。
如果用户取消选择原始项目但保留第二个项目,则现在需要删除不可见的线条。除了重复...
目前我的代码是:
'check for nothing selected
If Driver_Sel = "" Then
'nothing selected
lbl_driverID.Caption = ""
End If
If InStr(1, Driver_Sel, "PC-CR") <> 0 Then
'PCCR format
lbl_driverID.Visible = True
lbl_driverID.Caption = lbl_driverID.Caption & vbNewLine & "-PC-CR: use Format: PCCR-0000xxxx/001"
ElseIf Not InStr(1, Driver_Sel, "PC-CR") <> 0 Then
'remove PCCR
lbl_driverID.Visible = True
lbl_driverID.Caption = Replace(lbl_driverID.Caption, "-PC-CR: use Format: PCCR-0000xxxx/001", "")
End If
If InStr(1, Driver_Sel, "PRTS") <> 0 Then
'PRTS
lbl_driverID.Visible = True
lbl_driverID.Caption = lbl_driverID.Caption & vbNewLine & "-PRTS: include a PRTS#"
ElseIf Not InStr(1, Driver_Sel, "PRTS") <> 0 Then
'remove PCCR
lbl_driverID.Visible = True
lbl_driverID.Caption = Replace(lbl_driverID.Caption, "-PRTS: include a PRTS#", "")
End If
我认为这是因为我有标签的标题(蓝色文本)使用它的现有值,然后添加新项目..即使它是重复的。
我在这里有点难过...关于只显示一个笔记实例的任何帮助?
提前谢谢你!!
【问题讨论】:
-
每次用户选择或取消选择某些内容时,只需从选择中重建整个标题,而不是从标题中添加/删除。这会容易得多,而且标题总是适合选择。
标签: excel vba listbox userform