listbox1.additem syntax for multiple columns

  • Thread starter Thread starter Russ Robelen
  • Start date Start date
R

Russ Robelen

i am trying to load a two column listbox with the additem
method. The syntax for a single column listbox is:
listbox1.additem ("text")
For the life of me I cannot determine what the syntax is
for multiple columns. Can anyone help me.
 
To the amateur programmers like me who may read this thread, Tom was almost right. I think he meant for his code to read

ListBox1.Additem "Text
Listbox1.List(Listbox1.ListCount-1,1) = "Text2

A word of caution - a quick read of listbox controls might suggest that the following code would load a two column listbox1 (ColumnCount property set to 2) with
“Row 0 Column 0†in row 0, column 0 and “Row 0 Column 1†in row 0, column
“Row 1 Column 0†in row 1, column 0 and “Row 1 Column 1†in row 1, column

With userform
.ListBox1.Clea
For m = 0 to
.Listbox1.List(m, 0) = “Row “ & m & “ Column 0â€
.Listbox1.List(m, 1) = “Row †& m & “ Column 1â€
Nex
End wit

But it will not work. You will get a

Run-time error ‘381’ Could not set the List property. Invalid property array inde

The problem is .Listbox1.List(m, 0) = …. Cannot create a row but can only modify an existing row. You must preface this statement with the statement

..Listbox1.AddItem = “†‘a blank row or any other text string will wor

This statement creates a row that the following statements can then modify. What ever text string you add with the AddItem will be overwritten by the first statement that follows. The following code does work

With userform
.ListBox1.Clea
For m = 0 to
.Listbox1.AddItem = “â€
.Listbox1.List(m, 0) = “Row “ & m & “ Column 0â€
.Listbox1.List(m, 1) = “Row “ & m & “ Column 1â€
Nex
End wit

It took me more time than I care to admit to figure this out


----- Tom Ogilvy wrote: ----

ListBox1.Additem "Text
Listbox1.List(Listbox1.Count-1,1) = "Text2
 
Back
Top