Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default listbox1.additem syntax for multiple columns

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default listbox1.additem syntax for multiple columns

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

--
Regards,
Tom Ogilvy

"Russ Robelen" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default listbox1.additem syntax for multiple columns

ignore this - testing
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default listbox1.additem syntax for multiple columns

ignore this - testing
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ListBox1. add item myCell.entirerow Vikram Dhemare Excel Discussion (Misc queries) 3 April 8th 08 01:49 AM
UserForm:Resume to ListBox1 damorrison Excel Discussion (Misc queries) 2 August 26th 06 10:10 AM
Help with: ListBox1.AddItem (ws.Name) Ron de Bruin Excel Worksheet Functions 0 May 18th 05 07:02 PM
Multiple Column ComboBox using Additem Jimmi Excel Programming 2 September 24th 03 02:40 AM
(Worksheet)Listbox1.additem = (Form)Listbox1.value ?? Tom Ogilvy Excel Programming 0 September 2nd 03 07:36 PM


All times are GMT +1. The time now is 07:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"