I'm using Excel VBA to do this. But this sub seems to copy everything from sheet 1 to sheet 2? Please advise. I want only multiple selected items in ListBox to be copy. Does anyone know good VB site for beginner? ListBox guide? MSDN too deep for me.

Thanks for all!


VB Code:
  1. Sub GenSelectedSQL()
  2.     Dim rngColC As Range
  3.     Dim strFirstAddress As String
  4.     Dim rngNextResult As Range
  5.     Dim rngNextSearch As Range
  6.     Dim i As Long
  7.     Dim c As Long
  8.      
  9.     Set rngColC = Sheets("Sheet1").Range("C:C").CurrentRegion
  10.      
  11.     With UserForm1.ListBox1
  12.     For i = 0 To .ListCount - 1  ' first listbox index is 0!
  13.     Set rngNextResult = rngColC.Find(What:=ListBox1.List(i, 0), LookIn:=xlValues, LookAt:=xlWhole, _
  14.     SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
  15.     If Not rngNextResult Is Nothing Then
  16.      'copy row and paste it somewhere
  17.     rngNextResult.EntireRow.Copy Destination:=Worksheets("Sheet2").Cells(rngNextResult.Row, 1)
  18.     End If
  19.      'now if there's a match, find any others
  20.     If Not rngNextResult Is Nothing Then
  21.     Do  'change the search range to the remainder of the range
  22.     Set rngNextSearch = Range(rngNextResult, rngColC.End(xlDown))
  23.     Set rngNextResult = rngNextSearch.FindNext(rngNextResult)
  24.     strFirstAddress = rngNextResult.Address
  25.     If Not rngNextResult Is Nothing Then
  26.     rngNextResult.EntireRow.Copy Destination:=Worksheets("Sheet2").Cells(rngNextResult.Row, 1)
  27.     End If
  28.     Loop While Not rngNextResult Is Nothing And rngNextResult.Address <> strFirstAddress
  29.     End If
  30.     Next i
  31.     End With  
  32. End Sub