• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

print data in userform list box

Chihiro

Excel Ninja
There is no direct method. Easiest way is to transfer contents of Listbox into temp sheet and print from there.
 

Shanzil

New Member
This is my user form, im looking for when i hit transfer button all data in listbox will transfer to worksheet so i can print this as you described above.
i really appreciate your help.
62155
 

Kenneth Hobson

Active Member
If you want the full list, a scratch sheet can be printed with the list as Chihiro explained.

If we knew how the list was filled, there could be ways to print via a print area. If you want a screen snip of the userform, that can be done too.
 

Shanzil

New Member
This is th code im using for this userform.

Code:
Private Sub cmdCancel_Click()
Unload Me

End Sub

Private Sub cmdtransfer_Click()
Dim i  As Long
For i = 0 To ListBox1.ListCount - 1
Cells(i + 1, 1) = ListBox1(i)
Next i

End Sub

Private Sub ComboBox1_Change()
Dim database(1 To 100, 1 To 4)
Dim My_Range As Integer
Dim colum As Byte
On Error Resume Next
Ark3.Range("A2").AutoFilter field:=1, Criteria1:=Me.ComboBox1.Value


For i = 2 To Ark3.Range("A100000").End(xlUp).Row
If Ark3.Cells(i, 1) = Me.ComboBox1 Then

My_Range = My_Range + 1
For colum = 1 To 4
database(My_Range, colum) = Ark3.Cells(i, colum)
Next colum
End If
Next i
Me.ListBox1.List = database
End Sub

Private Sub CommandButton1_Click()
ComboBox1 = ""
ListBox1 = ""
'Dim ctl As Control
'For Each ctl In UserForm1.Controls
'If TypeName(ctl) = "combobox1" Or TypeName(ctl) = "listbox1" Then
'ctl.Value = ""
'End If
'Next ctl
End Sub

Private Sub UserForm_Click()

End Sub
 
Last edited by a moderator:

Belleke

Active Member
Like this?
Change Sheetname with the real name of your sheet where the listbox records have to go.
Put the code under a button, make sure the name of the button and the buttonname in the code are the same.
Code:
Private Sub CommandButton1_Click()
With Sheets("sheetname")
    .Range("A" & .Rows.Count).End(xlUp).Offset(1).Resize(ListBox1.ListCount) = ListBox1.List
End With
End Sub
 

Shanzil

New Member
Hi Belleke,

This transfer only the first row value 4 not the rest of the contents. i want this whole contents to be transferred.
62156
 

Chihiro

Excel Ninja
Hence, my request to upload sample. It's so much easier for us to help you, without it we will be guessing at few things.
Like how your ListBox is populated in the first place.

As for @Belleke 's code not bringing in all columns. You need to add # of columns you need in .Resize portion of his code.
Ex:
Code:
With Sheets("sheetname")
    .Range("A" & .Rows.Count).End(xlUp).Offset(1).Resize(ListBox1.ListCount, 4) = ListBox1.List
End With
 

Shanzil

New Member
I am tried but not getting, can you plz provide modified code. really appreciated
i tired different code :
Code:
dim ws As Worksheet
'Set ws = wb.Sheets("Ark1")
'Dim i As Long, rownum As Long

'rownum = 2

'For i = 0 To Me.ListBox1.ListCount - 1
'ws.Cells(rownum, 1).Value = Me.ListBox1.List(i)
'rownum = rownum + 1
'Next
End sub
same results :(
 
Last edited by a moderator:
Top