View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Russ Robelen[_2_] Russ Robelen[_2_] is offline
external usenet poster
 
Posts: 3
Default listbox1.additem syntax for multiple columns

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

--
Regards
Tom Ogilv

"Russ Robelen" wrote in messag
..
i am trying to load a two column listbox with the addite
method. The syntax for a single column listbox is
listbox1.additem ("text"
For the life of me I cannot determine what the syntax i
for multiple columns. Can anyone help me