troubleshooting Question

Loop through multiple records for new sheet

Avatar of leezac
leezac asked on
Visual Basic ClassicMicrosoft Excel
8 Comments1 Solution293 ViewsLast Modified:
I am trying to get this code to work to loop through a listbox that is multiselect and place the selections onto another sheet

I am getting an error 1004 on this line
ThisWorkbook.Sheets("Sheet2").Cells(lCurrentRow, 8).Offset(g, 0) = .List(gi)
_________________________________________________________________

Private Sub CommandButton1_Click()


Dim lItem As Long
Dim gi As Integer
Dim g As Integer

'Set x = 1
   For lItem = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(lItem) = True Then
           ThisWorkbook.Sheets("Sheet2").Cells(2, 3).Value = ListBox1.List(lItem)
           gi = 1
With ListBox1
For gi = 0 To .ListCount - 1
If .Selected(gi) = True Then
ThisWorkbook.Sheets("Sheet2").Cells(lCurrentRow, 8).Offset(g, 0) = .List(gi)
g = g + 1
End If
Next gi
End With
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros