Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone. I want to have 11 columns in my listbox. Can you help me?
jefferson
Solved! Go to Solution.
Hi everyone. I want to have 11 columns in my listbox. Can you help me?
Solved! Go to Solution.
You already have 11 columns when you set the ColumnCount property. The List property is used to set the contents of the List. In your sample, you are trying to set the list address of Row 0, Column 10 to an integer of 11. Note what help says:
VBA Help wrote:
Remarks
The List property works with the ListCount and ListIndex properties.Use List to access list items. A list is a variant array; each item in the list has a row number and a column number.
Hello @Ed__Jobe.
Thanks for your answer. Maybe you have given me the solution but I do not catch it. Columncount works from 1 to 10 but it does not work from 11 or more. I need 15 columns in my Listbox. Can you give me a vba code to have 15 columns in my listbox?
You can have 15 columns. See below. Remember that the column numbers are zero indexed. 0-14 = 15 columns. The ColumnCount property sets the number of columns, the List property sets the contents of the cell.
Here's an example of setting the List property.
Public Sub FillFileList()
'fill ListFiles list box with file names in StrDir global var
Dim strFileList() As String
Dim strFileName As String
Dim i As Integer
i = 0
ReDim strFileList(i)
strFileName = Dir(strDir + "*.scr")
While Not strFileName = ""
ReDim Preserve strFileList(i)
'store filename in array
strFileList(i) = strFileName
i = i + 1
'get next filename
strFileName = Dir()
Wend
ListFiles.List = strFileList
End Sub
So, your problem is with:
.List(0,10) = 11
You need to create an array with values to be assigned to the List method.
Private Sub UserForm_Initialize()
Dim strList(2, 2) As String
strList(0, 0) = "Col 1"
strList(0, 1) = "Col 2"
strList(0, 2) = "Col 3"
strList(1, 0) = "R1C1"
strList(1, 1) = "R1C2"
strList(1, 2) = "R1C3"
With ListBox1
.ColumnCount = 3
.ColumnWidths = "0.5 in;0.5 in;0.5 in"
.List = strList
End With
End Sub