I've a Listbox1 and users select items to move into Listbox2. I need to move everything from Listbox2 into Excel.
The Userform should then close Me and another Userform should be displayed (either UF1, UF2 or UF3; a formula in G3 calculates which new form should be displayed).
Private Sub CommandButton2_Click()
Dim i as integer
Dim LastRow As Long
LastRow = Sheets("EnteredData").Range("F" & Rows.Count).End(xlUp).Row
If Me.ListBox2.ListCount = 0 Then
MsgBox ("Please select at least one role")
Else
For i = 0 To ListBox2.ListCount - 1
Sheets("EnteredData").Range("F" & LastRow).Offset(1, 0).Value = ListBox2.List(i)
Me.ListBox2.RemoveItem i
Next i
End If
Unload Me
Sheets("EnteredData").Range("G3").Show
End Sub
The issues:
- If Listbox2 contains at least two items, Run-time error 381: Could not get the List property. Invalid property array index on line
Sheets("EnteredData").Range("F" & LastRow).Offset(1, 0).Value = ListBox2.List(i) - The 'next' Userform called in
Sheets("EnteredData").Range("G3").Showdoes not display the required form.Unload Meworks, but the new form (e.g. UF1) isn't shown.
Showis not a method of therangeobject. - SJRIfstatements. Regarding your clarification, I've got anIFstatement which ensures something is included in Listbox2. I now need transfer everything from Listbox2 to my Excel sheet. - Marc