I want to format a single column of a ListBox as Centered.
Is that possible?
CodePudding user response:
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:
I don't think dat VBA has a property to center allign 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 ;)
CodePudding user response:
A Userform listbox actually does dispose of a TextAlign
property to center align data.
Side note: generally this would apply the same format to all list columns, which might not be wanted in other occasions (e.g. for numeric data in additional columns).
Possible example assignment
Me.ListBox1.TextAlign = fmTextAlignCenter