Listbox print out how to set column width

Tayl4n

Board Regular
Joined
Feb 17, 2021
Messages
84
Office Version
  1. 2016
Platform
  1. Windows
Dear MrExcel community,

I search & fill listbox with textbox then I print listbox values with this code;

VBA Code:
Private Sub cmdPrint_Click()
If ListBox1.ListCount = 0 Then
MsgBox “There is no data for print”
Exit Sub
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i As Workbook
Set i = Workbooks.Add
Range(“A2”).Resize(ListBox1.ListCount, ListBox1.ColumnCount).Value = ListBox1.List
Unload Me
i.Sheets(1).ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & “\” & “List.pdf”
i.Close False

Listbox codes;
VBA Code:
Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 33
ListBox1.Liste = Range(“A2:AG750”).Value
VBA Code:
But some columns datas not fit. I need to set columns width.
Thank you for your time and interest!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Dear MrExcel community,

I search & fill listbox with textbox then I print listbox values with this code;

VBA Code:
Private Sub cmdPrint_Click()
If ListBox1.ListCount = 0 Then
MsgBox “There is no data for print”
Exit Sub
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i As Workbook
Set i = Workbooks.Add
Range(“A2”).Resize(ListBox1.ListCount, ListBox1.ColumnCount).Value = ListBox1.List
Unload Me
i.Sheets(1).ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & “\” & “List.pdf”
i.Close False

Listbox codes;
VBA Code:
Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 33
ListBox1.Liste = Range(“A2:AG750”).Value
VBA Code:
But some columns datas not fit. I need to set columns width.
Thank you for your time and interest!
VBA Code:
‘also searh and filter textbox codes about listbox

Me.ListBox1.Clear
Me.ListBox1.ColumnCount = 33
Me.ListBox1.ColumnHeads = False
Me.ListBox1.ColumnWidths = “”
 
Upvote 0
Actually
Are you trying to autofit the columns or make them manually adjustable?
Hey actually I manually setting with these codes but datas changing so autofit would be much better solution for me ??❤️

VBA Code:
i.Sheets(1).Range("D:D").columnwidth = 20  'change to suit
 
Upvote 0
Untested, but how about:

VBA Code:
With i.Sheets(1)
        With .PageSetup
             .Zoom = False 
             .FitToPagesTall = 1 
             .FitToPagesWide = 1
       End With
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & “\” & “List.pdf”
End With

Not sure if that'll work for PDF or not.
 
Upvote 0
Untested, but how about:

VBA Code:
With i.Sheets(1)
        With .PageSetup
             .Zoom = False
             .FitToPagesTall = 1
             .FitToPagesWide = 1
       End With
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & “\” & “List.pdf”
End With

Not sure if that'll work for PDF or not.
Unfortunately not work :(
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top