View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Won't Add Multicolumn Data

My oversight, the method I suggested only works for up to 10 columns:

Private Sub UserForm_Initialize()
Dim a(1 To 10) As Long
With lstResult
.ColumnCount = 10
.ColumnWidths = "75;75;75;75;75;75;75;75;75;75;75;75;75"
For i = 1 To 25 ' 25 rows
For j = 1 To 10 ' 10 columns
' populate the array with dummy values
' for testing
a(j) = Int(Rnd() * 100 + 1)
Next
.AddItem a(i)
For j = 2 To 10
.List(.ListCount - 1, j - 1) = a(j)
Next
Next
End With
End Sub

For 13 columns, you will need to populate your data like this:

Private Sub UserForm_Initialize()
Dim a(1 To 25, 1 To 13) As Long
With lstResult
.ColumnCount = 13
.ColumnWidths = "75;75;75;75;75;75;75;75;75;75;75;75;75"
For i = 1 To 25 ' 25 rows
For j = 1 To 13 ' 13 columns
a(i, j) = Int(Rnd() * 100 + 1)
Next
Next
' assign the 25 x 13 array to list all at once
.List = a
End With
End Sub


--
Regards,
Tom Ogilvy

"Brandon Johnson" wrote:

thanks for the reply. however it throws me a runtime 381 error when it
trys to fire off the .list property. any thoughts?

Tom Ogilvy wrote:
With lstResults
.AddItem A(1)
for j = 2 to 13
.List(.Listcount-1,j - 1) = A(j)
Next
end With

--
Regards,
Tom Ogilvy


"Brandon Johnson" wrote:

It lists all the data in the first cell

Brandon Johnson wrote:
I jsut need to be able to add these values to the listbox. I have 13
columns and is set to 75 pt column width.

lstResults.AddItem A(1) & ";" & A(2) & ";" & A(3) & ";" & A(4) & ";" &
A(5) & ";" & A(6) & ";" & A(7) & ";" & A(8) & ";" & A(9) & ";" & A(10)
& ";" & A(11) & ";" & A(12) & ";" & A(13)