list box columns not transferring

  • Thread starter Thread starter pcscsr
  • Start date Start date
P

pcscsr

I have a multi column (4) list box with the following columns:

Botanical Name Common Name size price

the following code transferrs the columns from the list box to
separate worksheet

Private Sub CommandButton1_Click()
Dim i As Integer, x As Integer
i = 2
Sheets("sheet2").Range("a:d").EntireColumn.ClearContents
With ListBox1
For x = 0 To .ListCount - 1
If .Selected(x) = True Then
Sheets("sheet2").Cells(i, 1) = .List(x, 0)
i = i + 1
End If
Next x
End With
UserForm1.Hide
End Sub


The code works however it only transferrs the 1st column "Botanica
Name" and not the other three.

How can I modify this so that it also transfers the other thre
columns. I am on a deadline for work and this is the only thing tha
is holding me up from completing my project
 
Uh, 2 loops?

For x = 0 To .ListCount - 1
If .Selected(x) = True Then
For j = 1 To .ColumnCount
Sheets("sheet2").Cells(i, j).Value = .List(x, j - 1)
Next j
i = i + 1
End If
Next x


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Back
Top