Hi all,

I have a listbox in a userform with several columns.
I’m trying to set up a code for transfer button, which allow me to copy the selected rows in a listbox and to past them in the excel sheet.
With the following code I can transfer all the rows in listbox, but I want to transfer only the selected rows. For example I highlight the first rows and click the transfer button to copy the rows in the excel sheet "results" and then the second row etc..

Any help will be grateful

Thank you in advance


Private Sub TransferButton_Click()
    Dim ws As Worksheet
    Set ws = Sheets("Results")
  Dim nextAvailableRow As Long
    Dim i As Long
    For i = 0 To ListBox1.ListCount - 1
        nextAvailableRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
        ws.Range("A" & nextAvailableRow) = ListBox1.Column(0, i)
        ws.Range("B" & nextAvailableRow) = ListBox1.Column(1, i)
        ws.Range("C" & nextAvailableRow) = ListBox1.Column(2, i)
        ws.Range("D" & nextAvailableRow) = ListBox1.Column(3, i)
        ws.Range("E" & nextAvailableRow) = ListBox1.Column(4, i)
        ws.Range("F" & nextAvailableRow) = ListBox1.Column(5, i)
        ws.Range("G" & nextAvailableRow) = ListBox1.Column(6, i)
        ws.Range("H" & nextAvailableRow) = ListBox1.Column(7, i)
        ws.Range("I" & nextAvailableRow) = ListBox1.Column(8, i)
        ws.Range("J" & nextAvailableRow) = ListBox1.Column(9, i)
        ws.Range("K" & nextAvailableRow) = ListBox1.Column(10, i)
        ws.Range("L" & nextAvailableRow) = ListBox1.Column(11, i)
        ws.Range("M" & nextAvailableRow) = ListBox1.Column(12, i)
        ws.Range("N" & nextAvailableRow) = ListBox1.Column(13, i)
        ws.Range("O" & nextAvailableRow) = ListBox1.Column(14, i)
        ws.Range("P" & nextAvailableRow) = ListBox1.Column(15, i)
        ws.Range("Q" & nextAvailableRow) = ListBox1.Column(16, i)
        ws.Range("R" & nextAvailableRow) = ListBox1.Column(17, i)
        ws.Range("S" & nextAvailableRow) = ListBox1.Column(18, i)
         ws.Range("T" & nextAvailableRow) = ListBox1.Column(19, i)
         ' ws.Range("U" & nextAvailableRow) = ListBox1.Column(20, i)
'           ws.Range("V" & nextAvailableRow) = ListBox1.Column(21, i)
           ' ws.Range("W" & nextAvailableRow) = ListBox1.Column(22, i)
    Next i

End Sub