Search code examples
excelvbauserform

Is it possible to format (center aligned) a single column of a ListBox?


I want to format a single column of a ListBox as Centered.

Is that possible?


Solution

  • Perhaps you can work around it. If you make a listbox containing 3 columns each with the same column width and you fill column 1 and 3 with nothing or one space and you fill column 2 with data, than it is centered in a way:

    Private Sub UserForm_Initialize()
    
        With Me.lstBox
            .ColumnCount = 3
            .ColumnWidths = 10
            .BoundColumn = 2
            .AddItem
            .List(0, 1) = "Example"
        End With
    
    End Sub
    

    Above code results in:

    enter image description here

    I don't think dat VBA has a property to center align data in a listbox (I read that VB6 does have it by the way). But this is not a single column I'll give you that ;)