Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

ListBox "Column" property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 18 Jan 2007 04:32 GMT
VBA Help says:

     Column Property

Specifies one or more items in a ListBox or ComboBox.

Syntax

object.Column( column, row ) [= Variant]

The Column property syntax has these parts:

     Part Description
     object Required. A valid object.
     column Optional. An integer with a range from 0 to one less than the total number of columns.
     row Optional. An integer with a range from 0 to one less than the total number of rows.
     Variant Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

Settings

If you specify both the column and row values, Column reads or writes a specific item.

If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox.

____________________________________

So it seems to me that I should be able to use this property to populate individual columns in a multi-column Listbox.  I see how:

ListBox1.Column(0, 0) = "My Text"   'writes "My Text" to column 1 row 1

and how:

Dim myArray
Listbox1.ColumnCount = 4
myArray = Split("A|B|C|D", "|")
ListBox1.Column = myArray   'writes a one row x four column entry   A  B  C  D

I can't seem to figure out how to specify a "single column of values."  The help clearly states that the Variant is used to specify a single value, "a column of values", or a two-dimensional array.

What do I use as the "Variant" and how do I write the code to populate a single column in a multi-column Listbox using the .Column property?  All attempts like:

ListBox1.Column(3) = ?????  fail.

Thanks

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Perry - 20 Jan 2007 13:46 GMT
Following statement changes single column 3.
Once a selection is made, the following lines execute.

   If ComboBox1.ListIndex > -1 Then
       ComboBox1.Column(3) = "some value"
   End If

PLs repost if y're looking for something else
Krgrds,
Perry

 VBA Help says:

       Column Property

 Specifies one or more items in a ListBox or ComboBox.

 Syntax

 object.Column( column, row ) [= Variant]

 The Column property syntax has these parts:

       Part Description
       object Required. A valid object.
       column Optional. An integer with a range from 0 to one less than the total number of columns.
       row Optional. An integer with a range from 0 to one less than the total number of rows.
       Variant Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

 Settings

 If you specify both the column and row values, Column reads or writes a specific item.

 If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox.

 ____________________________________

 So it seems to me that I should be able to use this property to populate individual columns in a multi-column Listbox.  I see how:

 ListBox1.Column(0, 0) = "My Text"   'writes "My Text" to column 1 row 1

 and how:

 Dim myArray
 Listbox1.ColumnCount = 4
 myArray = Split("A|B|C|D", "|")
 ListBox1.Column = myArray   'writes a one row x four column entry   A  B  C  D

 I can't seem to figure out how to specify a "single column of values."  The help clearly states that the Variant is used to specify a single value, "a column of values", or a two-dimensional array.

 What do I use as the "Variant" and how do I write the code to populate a single column in a multi-column Listbox using the .Column property?  All attempts like:

 ListBox1.Column(3) = ?????  fail.

 Thanks

 --
 Greg Maxey/Word MVP
 See:
 http://gregmaxey.mvps.org/word_tips.htm
 For some helpful tips using Word.
Greg Maxey - 20 Jan 2007 14:36 GMT
Perry,

Say I have two column listbox. I can load a list of US state names in column 1 and the abbreviation in column 2 using the following code.

Private Sub UserForm_Initialize()
Dim myArray1 As Variant
Dim myArray2 As Variant
Dim i As Long
myArray1 = Split("Select State|Alabama|Alaska|Arizona|" _
          & "Arkansas|California|Connecticut|Etc.", "|")
myArray2 = Split(" |AL|AK|AZ|AR|CA|CT|Etc", "|")
ListBox1.ColumnWidths = "60;0"
For i = 0 To UBound(myArray1)
 ListBox1.AddItem
 ListBox1.List(i, 0) = myArray1(i)
 ListBox1.List(i, 1) = myArray2(i)
Next i
End Sub

Now, based on the Help file statement:

If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox

It seems that I should be able to insert the following line before the end sub statement above and change the ListBox1 "column of values"

ListBox1.Column(0) = myArray2

It just doesn't work.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

 Following statement changes single column 3.
 Once a selection is made, the following lines execute.

     If ComboBox1.ListIndex > -1 Then
         ComboBox1.Column(3) = "some value"
     End If

 PLs repost if y're looking for something else
 Krgrds,
 Perry

   "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> schreef in bericht news:%23qsggnrOHHA.2312@TK2MSFTNGP04.phx.gbl...
   VBA Help says:

         Column Property

   Specifies one or more items in a ListBox or ComboBox.

   Syntax

   object.Column( column, row ) [= Variant]

   The Column property syntax has these parts:

         Part Description
         object Required. A valid object.
         column Optional. An integer with a range from 0 to one less than the total number of columns.
         row Optional. An integer with a range from 0 to one less than the total number of rows.
         Variant Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

   Settings

   If you specify both the column and row values, Column reads or writes a specific item.

   If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox.

   ____________________________________

   So it seems to me that I should be able to use this property to populate individual columns in a multi-column Listbox.  I see how:

   ListBox1.Column(0, 0) = "My Text"   'writes "My Text" to column 1 row 1

   and how:

   Dim myArray
   Listbox1.ColumnCount = 4
   myArray = Split("A|B|C|D", "|")
   ListBox1.Column = myArray   'writes a one row x four column entry   A  B  C  D

   I can't seem to figure out how to specify a "single column of values."  The help clearly states that the Variant is used to specify a single value, "a column of values", or a two-dimensional array.

   What do I use as the "Variant" and how do I write the code to populate a single column in a multi-column Listbox using the .Column property?  All attempts like:

   ListBox1.Column(3) = ?????  fail.

   Thanks

   --
   Greg Maxey/Word MVP
   See:
   http://gregmaxey.mvps.org/word_tips.htm
   For some helpful tips using Word.
Perry - 20 Jan 2007 17:39 GMT
I don't see the point in first assigning second column value using the List() property and
at same time trying to change second column values using the Column() property...
But I take it, y're looking at it from "VBA-squeeze" point of view ...(?)
;-)

I'm afraid y'll have to change the values in the entire array and pass this (changed) array to the listbox.

Variant has to be passed to the .Column property because it has 3 overridables under the hood:
1) .Column -> (without params)
2) .Column(OneParam) -> (with one parameter)
3) .Column(1stParam, 2ndParam) -> (two parameters)

First one takes an array, and passes all values to all rows, all columns (transposed) in yr listbox
Second one, takes a single value (also Variant btw) to populate a designated column in current row
Last one, takes a single value (also Variant btw) to populate a designated column in a designated row

Krgrds,
Perry
 Perry,

 Say I have two column listbox. I can load a list of US state names in column 1 and the abbreviation in column 2 using the following code.

 Private Sub UserForm_Initialize()
 Dim myArray1 As Variant
 Dim myArray2 As Variant
 Dim i As Long
 myArray1 = Split("Select State|Alabama|Alaska|Arizona|" _
            & "Arkansas|California|Connecticut|Etc.", "|")
 myArray2 = Split(" |AL|AK|AZ|AR|CA|CT|Etc", "|")
 ListBox1.ColumnWidths = "60;0"
 For i = 0 To UBound(myArray1)
   ListBox1.AddItem
   ListBox1.List(i, 0) = myArray1(i)
   ListBox1.List(i, 1) = myArray2(i)
 Next i
 End Sub

 Now, based on the Help file statement:

 If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox

 It seems that I should be able to insert the following line before the end sub statement above and change the ListBox1 "column of values"

 ListBox1.Column(0) = myArray2

 It just doesn't work.

 --
 Greg Maxey/Word MVP
 See:
 http://gregmaxey.mvps.org/word_tips.htm
 For some helpful tips using Word.

   "Perry" <drumper@gmail.com> wrote in message news:%233NDylJPHHA.448@TK2MSFTNGP04.phx.gbl...
   Following statement changes single column 3.
   Once a selection is made, the following lines execute.

       If ComboBox1.ListIndex > -1 Then
           ComboBox1.Column(3) = "some value"
       End If

   PLs repost if y're looking for something else
   Krgrds,
   Perry

     "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> schreef in bericht news:%23qsggnrOHHA.2312@TK2MSFTNGP04.phx.gbl...
     VBA Help says:

           Column Property

     Specifies one or more items in a ListBox or ComboBox.

     Syntax

     object.Column( column, row ) [= Variant]

     The Column property syntax has these parts:

           Part Description
           object Required. A valid object.
           column Optional. An integer with a range from 0 to one less than the total number of columns.
           row Optional. An integer with a range from 0 to one less than the total number of rows.
           Variant Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

     Settings

     If you specify both the column and row values, Column reads or writes a specific item.

     If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox.

     ____________________________________

     So it seems to me that I should be able to use this property to populate individual columns in a multi-column Listbox.  I see how:

     ListBox1.Column(0, 0) = "My Text"   'writes "My Text" to column 1 row 1

     and how:

     Dim myArray
     Listbox1.ColumnCount = 4
     myArray = Split("A|B|C|D", "|")
     ListBox1.Column = myArray   'writes a one row x four column entry   A  B  C  D

     I can't seem to figure out how to specify a "single column of values."  The help clearly states that the Variant is used to specify a single value, "a column of values", or a two-dimensional array.

     What do I use as the "Variant" and how do I write the code to populate a single column in a multi-column Listbox using the .Column property?  All attempts like:

     ListBox1.Column(3) = ?????  fail.

     Thanks

     --
     Greg Maxey/Word MVP
     See:
     http://gregmaxey.mvps.org/word_tips.htm
     For some helpful tips using Word.
Greg Maxey - 20 Jan 2007 18:58 GMT
Perry.

Thanks for your reply.  Yes I was just showing that I could create and populate the necessary rows and columns using list but then couldn't change "a column of values" using column.  What I believe the help file says is that the below code should work.  Well it doesn't and therefore I resigned to believe that the phrase "column of values" in
the help file statement:  
     Variant Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

is a misprint.

Private Sub UserForm_Initialize()
Dim myArray1 As Variant
Dim myArray2 As Variant
Dim i As Long
myArray1 = Split("Select State|Alabama|Alaska|Arizona|" _
          & "Arkansas|California|Connecticut|Etc.", "|")
myArray2 = Split(" |AL|AK|AZ|AR|CA|CT|Etc", "|")
ListBox1.ColumnWidths = "60;0"
For i = 0 To UBound(myArray1)
 ListBox1.AddItem
Next i
ListBox1.Column(0) = myArray1
ListBox1.Column(1) = myArray2
Next i
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

 I don't see the point in first assigning second column value using the List() property and
 at same time trying to change second column values using the Column() property...
 But I take it, y're looking at it from "VBA-squeeze" point of view ...(?)
 ;-)

 I'm afraid y'll have to change the values in the entire array and pass this (changed) array to the listbox.

 Variant has to be passed to the .Column property because it has 3 overridables under the hood:
 1) .Column -> (without params)
 2) .Column(OneParam) -> (with one parameter)
 3) .Column(1stParam, 2ndParam) -> (two parameters)

 First one takes an array, and passes all values to all rows, all columns (transposed) in yr listbox
 Second one, takes a single value (also Variant btw) to populate a designated column in current row
 Last one, takes a single value (also Variant btw) to populate a designated column in a designated row

 Krgrds,
 Perry
   "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> schreef in bericht news:%23jpwzCKPHHA.4800@TK2MSFTNGP05.phx.gbl...
   Perry,

   Say I have two column listbox. I can load a list of US state names in column 1 and the abbreviation in column 2 using the following code.

   Private Sub UserForm_Initialize()
   Dim myArray1 As Variant
   Dim myArray2 As Variant
   Dim i As Long
   myArray1 = Split("Select State|Alabama|Alaska|Arizona|" _
              & "Arkansas|California|Connecticut|Etc.", "|")
   myArray2 = Split(" |AL|AK|AZ|AR|CA|CT|Etc", "|")
   ListBox1.ColumnWidths = "60;0"
   For i = 0 To UBound(myArray1)
     ListBox1.AddItem
     ListBox1.List(i, 0) = myArray1(i)
     ListBox1.List(i, 1) = myArray2(i)
   Next i
   End Sub

   Now, based on the Help file statement:

   If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox

   It seems that I should be able to insert the following line before the end sub statement above and change the ListBox1 "column of values"

   ListBox1.Column(0) = myArray2

   It just doesn't work.

   --
   Greg Maxey/Word MVP
   See:
   http://gregmaxey.mvps.org/word_tips.htm
   For some helpful tips using Word.

     "Perry" <drumper@gmail.com> wrote in message news:%233NDylJPHHA.448@TK2MSFTNGP04.phx.gbl...
     Following statement changes single column 3.
     Once a selection is made, the following lines execute.

         If ComboBox1.ListIndex > -1 Then
             ComboBox1.Column(3) = "some value"
         End If

     PLs repost if y're looking for something else
     Krgrds,
     Perry

       "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> schreef in bericht news:%23qsggnrOHHA.2312@TK2MSFTNGP04.phx.gbl...
       VBA Help says:

             Column Property

       Specifies one or more items in a ListBox or ComboBox.

       Syntax

       object.Column( column, row ) [= Variant]

       The Column property syntax has these parts:

             Part Description
             object Required. A valid object.
             column Optional. An integer with a range from 0 to one less than the total number of columns.
             row Optional. An integer with a range from 0 to one less than the total number of rows.
             Variant Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

       Settings

       If you specify both the column and row values, Column reads or writes a specific item.

       If you specify only the column value, the Column property reads or writes the specified column in the current row of the object. For example, MyListBox.Column (3) reads or writes the third column in MyListBox.

       ____________________________________

       So it seems to me that I should be able to use this property to populate individual columns in a multi-column Listbox.  I see how:

       ListBox1.Column(0, 0) = "My Text"   'writes "My Text" to column 1 row 1

       and how:

       Dim myArray
       Listbox1.ColumnCount = 4
       myArray = Split("A|B|C|D", "|")
       ListBox1.Column = myArray   'writes a one row x four column entry   A  B  C  D

       I can't seem to figure out how to specify a "single column of values."  The help clearly states that the Variant is used to specify a single value, "a column of values", or a two-dimensional array.

       What do I use as the "Variant" and how do I write the code to populate a single column in a multi-column Listbox using the .Column property?  All attempts like:

       ListBox1.Column(3) = ?????  fail.

       Thanks

       --
       Greg Maxey/Word MVP
       See:
       http://gregmaxey.mvps.org/word_tips.htm
       For some helpful tips using Word.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.