PDA

View Full Version : Set UserForm Listbox Column Widths



gmaxey
02-08-2014, 12:39 PM
I have a listbox on a userform that has a variable number of columns typically over 30. I only want to display the first 3.

Is there a syntax that I can use to simplify setting the .ColumnWidths property?

0;60;150;????

Literally:
Set column 0 width = 0; Column 1 width = 60; Column 2 width = 150; and all others = 0

I'm currently doing it with code as follows:


For lngCount = 0 To ListBox1.ColumnCount - 1
Select Case lngCount
Case 0
strColWidth = "0;"
Case 1
strColWidth = strColWidth & "60;"
Case 2
strColWidth = strColWidth & "150;"
Case Else
strColWidth = strColWidth & "0;"
End Select
Next lngCount
With ListBox1
.ListIndex = -1
.ColumnWidths = strColWidth
End With

westconn1
02-08-2014, 04:48 PM
you can simplify it a bit


For l = 3 To ListBox1.ColumnCount - 1
strcolwidth = strcolwidth & ";0"
Next
strcolwidth = "0;60;150" & strcolwidth
ListBox1.ColumnWidths = strcolwidth

gmaxey
02-09-2014, 01:15 AM
westconn1,

Very nice. Thanks. Still I was hoping to find syntax (e.g., "0;60;150;0; ... ;0" that I could just type into the properties field and avoid using VBA. No big deal though and this works nicely.