从ListBox1中的选定项目中,我需要将项目添加到ListBox2中。
ListBox1-从“数据库”工作表中填充-[名称],[旧编号] // //从用户窗体文本框2提取的[日期]
列表框2-用于新预订-[名称],[日期],[新编号] [new_number]来自Userform文本框6
-如果Listbox1已经具有[名称],[日期],[旧编号],我想使用msgbox提示符“继续/跳过”来更新记录。
-如果ListBox2已经包含[名称],并且[日期]将通知用户修改
-如果Listbox2不包含[名称]和[日期],并且[new_number]将添加项目到集合中。
我的excel没有 .Items。包含函数,我不确定为什么。
Dim iCtr As Long
'If TextBox6.Value = "" Then ' check if textbox6 - contract/attendance is empty
' ans = MsgBox("Book for is empty. Are you sure?", vbYesNo, "Mr.Rubber")
' Select Case ans
' Case vbYes
' Case vbNo
' Exit Sub
' End Select
' End If
If ListBox1.Selected(iCtr) Then ' for each selected item in listbox1
If ListBox2.ListCount - 1 = -1 Then ' to add first item to listbox2
a = 1
Else
a = ListBox2.ListCount
End If
For i = 0 To a - 1
If ListBox2.List(i, 0) & ListBox2.List(i, 1) = ListBox1.List(iCtr, 0) & TextBox2 Then
ans = MsgBox("Data already exist. This will amend current data." & vbNewLine & "Do you want to continue?", vbYesNo, "Mr.Rubber")
Select Case ans
Case vbYes
GoTo carryon
Case vbNo
Exit Sub
End Select
carryon:
Else
.ListBox2.AddItem
ListBox2.List(i, 0) = ListBox1.List(iCtr, 0)
ListBox2.List(i, 1) = TextBox2
ListBox2.List(i, 2) = TextBox6.Value
End If
Next i
End If
Next iCtr
如果再次运行代码,则Listbox2数据将被新数据覆盖。 我想保留旧的唯一数据并将新数据添加到Listbox2集合中,然后再添加到工作表数据库中。
我们将不胜感激。
谢谢