ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   print listbox contents (https://www.excelbanter.com/excel-programming/275278-re-print-listbox-contents.html)

Dave Peterson[_3_]

print listbox contents
 
Maybe just loop through the contents (write to a temporary worksheet) and then
print that:

Option Explicit
Private Sub CommandButton1_Click()

Dim i As Long
Dim j As Long

For i = 0 To Me.ListBox1.ListCount - 1
For j = 0 To Me.ListBox1.ColumnCount - 1
MsgBox Me.ListBox1.List(i, j)
Next j
Next i

End Sub
Private Sub UserForm_Initialize()

Dim i As Long
Dim j As Long

With Me.ListBox1
.ColumnCount = 10
.ColumnWidths = 0.3
For i = 1 To 5
.AddItem Worksheets("sheet1").Cells(i, "A").Value
For j = 1 To 9
.List(.ListCount - 1, j) _
= Worksheets("sheet1").Cells(i, "A").Offset(0, j).Value
Next j
Next i
End With

End Sub


GUS wrote:

How can i print th contents of a listbox with 10 columns ?


--

Dave Peterson


Dave Peterson[_3_]

print listbox contents
 
I like Tom's answer to your later post better than the looping I did.

Dave Peterson wrote:

Maybe just loop through the contents (write to a temporary worksheet) and then
print that:

Option Explicit
Private Sub CommandButton1_Click()

Dim i As Long
Dim j As Long

For i = 0 To Me.ListBox1.ListCount - 1
For j = 0 To Me.ListBox1.ColumnCount - 1
MsgBox Me.ListBox1.List(i, j)
Next j
Next i

End Sub
Private Sub UserForm_Initialize()

Dim i As Long
Dim j As Long

With Me.ListBox1
.ColumnCount = 10
.ColumnWidths = 0.3
For i = 1 To 5
.AddItem Worksheets("sheet1").Cells(i, "A").Value
For j = 1 To 9
.List(.ListCount - 1, j) _
= Worksheets("sheet1").Cells(i, "A").Offset(0, j).Value
Next j
Next i
End With

End Sub

GUS wrote:

How can i print th contents of a listbox with 10 columns ?


--

Dave Peterson


--

Dave Peterson



All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com