col width in listbox

Hans810

Board Regular
Joined
Dec 1, 2005
Messages
63
Hi there,

I have a listbox with an Artlist: ListBox1.List() = Artlist

The listbox has 3 columns.

The columns are spaced out at a fixed dimension.
How can I adjust the spacing of the columns??
Now they are too far apart from eachother so my listbox is quite wide.

I know I have to do something like listbox1.columnwidths .... but what are the attributes???
I cannot find that in the "Help". Or at least, the "Help" is not clear about that!!

Pls give an example.

Thanks in advance for the help!!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Greetings Hans,

While you are in design mode, select the listbox and in the properties window, look for ColumnWidths as you mentioned. You can set the column widths there one of several ways.

By default, lets say you type in: 50;60;50 and press the enter key - Excel will convert it to: 49.95 pt;60 pt;49.95 pt

If you use points (like above) there are 72 per inch.

As to Help, if you click F1 while in the column widths box, it should take you right to the topic.

To set the ColumnWidths at runtime, something like:
Code:
Private Sub UserForm_Initialize()
    With ListBox1
        .ColumnCount = 3
        .ColumnWidths = "49.95 pt;60 pt;49.95 pt"
        ' other stuff as desired
    End With
        
End Sub

Please note that it is a string, so the quotes are required.

Hope this helps,

Mark
 
Upvote 0
Hi mark,

Thx for your respons.
I still have not got it working!!
I used the command as mentioned below, but still the default settings are in place.


the code I used:

ListBox1.List() = Artlist
With ColumnWidths = "30 pt;30 pt;90 pt"
End With

BR hans
 
Upvote 0
With ColumnWidths(...) is wrong because of absense the referenced object. i.e the ListBox1
Use: ListBox1.ColumnWidths(...) instead

The unit "pt" can be wrong in some language localizations and Excel versions.
Unit "pt" could be excluded at all with the same result.
Just write only numbers: ListBox1.ColumnWidths = "30;30;90"

Something like this could work:
Rich (BB code):
<font face=Courier New>
Private Sub UserForm_Initialize()
    Dim Artlist(1 To 10, 1 To 3)
    Artlist(1, 1) = 1.1
    Artlist(1, 2) = 1.2
    Artlist(1, 3) = 1.3
    Artlist(2, 2) = 2.2
    Artlist(3, 3) = 3.3
    With ListBox1
        .List = Artlist
        .ColumnCount = 3
        .ColumnWidths = "30;30;90"
        .ListIndex = 0
    End With
End Sub
</FONT>
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,037
Members
448,543
Latest member
MartinLarkin

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