See if this will get you started.
You really should learn how to declare your objects. It will payoff in the long run.
THere's no need to deselect the listbox items as you iterate the list. While if this instance, it won't cause any problems, if you ever have a listbox_click event, every time you deselect an item, would cause the click event to be called. Then you're chasing gremlins.
I made the code dynamic on the course list. Meaning, you can add to it and the code will accommodate the extra class.
HTH!
Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim WSSrc As Worksheet
Dim lItem As Long
Dim A As Long
Dim Rng As Range
Dim NextRow As Long
Dim LastRow As Long
'Get List of classes from sheet 2
Set WSSrc = Worksheets("Sheet2")
With WSSrc
LastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
Set Rng = .Range("B2:B" & LastRow)
End With
'Define Destination sheet
Set WS = Worksheets("Sheet1")
With WS
'Lastrow + 1 from Column B
NextRow = .Cells(.Rows.Count, 2).End(xlUp).Row + 1
'Iterate listbox
For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then
'Insert Project to sheet
WS.Range("A" & NextRow) = ListBox1.List(lItem)
'Iterate Project list and insert to sheet.
For A = 1 To Rng.Rows.Count
WS.Range("B" & NextRow) = Rng(A)
WS.Range("C" & NextRow) = Me.TextBox1
WS.Range("D" & NextRow) = Me.TextBox2
'Increment next row
NextRow = NextRow + 1
Next
End If
Next
End With
Unload Me
End Sub
Bookmarks