• 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.

AutoFit column listbox

Without an example?
Something like this?
Adapt to your needs
Code:
Private Sub UserForm_Initialize()
        Dim rngDB As Range, rng As Range
        Dim sWidth As String
        Dim vR() As Variant
        Dim n As Integer

        Set rngDB = Range("a1:ab1")
        For Each rng In rngDB
            n = n + 1
            ReDim Preserve vR(1 To n)
            vR(n) = rng.EntireColumn.Width
        Next rng
        sWidth = Join(vR, ";")
        Debug.Print sWidth
        With ListBox1
            .ColumnCount = 28
            .ColumnWidths = sWidth
            .RowSource = "A1:AB2"
            .BorderStyle = fmBorderStyleSingle
        End With
    End Sub
 
>>> use code - tags <<<
Code:
Set rngDB = Range("a1:ab1")
Table data
Sheets(1).ListObjects(1)
 
Last edited by a moderator:
It worked like this
>>> use code - tags <<<
Code:
Sheets(1).ListObjects(1).DataBodyRange
In some columns the last letter is halfway
 
Last edited by a moderator:
Use in Register or Change
>>> use code - tags <<<
Code:
Sheets(1).UsedRange.EntireColumn.AutoFit
Sheets(1).EnableSelection = xlNoSelection
The column is the exact width
 
Last edited by a moderator:
Back
Top