从列表框(主工作表)中获取所选项目,并将其显示在Userform-VBA上的列表框中
我试图从主工作表上的列表框中获取所选项目,并在用户表单上的列表框中获取这些所选项目 这是代码从列表框(主工作表)中获取所选项目,并将其显示在Userform-VBA上的列表框中,vba,excel,Vba,Excel,我试图从主工作表上的列表框中获取所选项目,并在用户表单上的列表框中获取这些所选项目 这是代码 Sub Viewselectshow() For lItem = 0 To Sheets("Main").Ent_ListBox.ListCount - 1 If Sheets("Main").Ent_ListBox.Selected(lItem) = True Then ItemReq = Sheets("Main").Ent_ListBox.Selec
Sub Viewselectshow()
For lItem = 0 To Sheets("Main").Ent_ListBox.ListCount - 1
If Sheets("Main").Ent_ListBox.Selected(lItem) = True Then
ItemReq = Sheets("Main").Ent_ListBox.Selected(lItem)
ViewSelectedEntitlements.ViewEntitlementListbox.AddItem ItemReq
End If
Next
ViewSelectedEntitlements.Show
End Sub
它可以工作,但在Userform的列表框中显示的值为-1,这显然不是所选项目。所选项目是CaraPhone。任何建议,请分享您的想法。因此您需要使用ItemReq=SheetsMain.Ent\u ListBox.ListlItem,而不是ItemReq=SheetsMain.Ent\u ListBox.SelectedlItem。SelectedlItem似乎是在处理索引,而不是try ItemReq=SheetsMain.Ent\u ListBox.SelectedlItem.ValueNo,我尝试了.Value方法,但它对我无效。ItemReq=SheetsMain.Ent\u ListBox.ListlItem