title: Loop through listboxes in excel vba
body: <p>Is there an apparent problem with the following codes? I want to loop through all listboxes and populate selected items. </p>
  
  <pre><code>Dim lRw As Integer
  Dim iX As Integer, iY As Integer
  Dim i As Integer
  
  For i = 1 To 10
  
  With ActiveSheet
  .Columns(i + 10).ClearContents
  End With
  
      For iX = 0 To ListBox(i).ListCount - 1
          If ListBox(i).Selected(iX) = True Then
          With Sheet1
              lRw = .Cells(.Rows.Count, i + 11).End(xlUp).Row + 1
              For iY = 0 To ListBox(i).ColumnCount - 1
                  .Cells(lRw, iY + i).Value = ListBox(i).List(iX, iY)
              Next iY
          End With
  
          End If
      Next iX
  Next i
  </code></pre>