Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ListBox AddItem method (2000)

    Is it possible to add items to a multicolumn listbox using the additem method or must I use an array? If so, how must I read the variables "strInfDate" and "strOOF" into an array? Below it adds both items to the same line, but I would like to separate the two items and line them up in the two columns.

    <pre>Sub PostFileDates()
    'Loops through sheets returns latest info date
    On Error Resume Next
    Dim oSheet As Worksheet
    Dim oBook As Workbook
    Dim strInfDate As String
    Dim strOOF As String
    Dim typInfDate As Date
    For Each oSheet In ThisWorkbook.Sheets
    If oSheet.QueryTables.Count > 0 Then
    oSheet.Activate
    For Each cell In oSheet.Range("aj46:b46")
    If cell.Value = 0 Then
    If Left(cell.Offset(-42, -1), 4) = "Week" Then
    strInfDate = cell.Offset(-42, -2).Value
    End If
    If Left(cell.Offset(-42, -1), 4) <> "Week" Then
    strInfDate = cell.Offset(-42, -1).Value
    End If
    strOOF = oSheet.Name
    'add items to listbox
    <font color=red>FInfo.ListBox1.AddItem strOOF & strInfDate</font color=red>
    Exit For
    End If
    Next cell
    End If
    Next oSheet
    FInfo.Show
    End Sub
    </pre>


  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ListBox AddItem method (2000)

    Mike, as you discovered, multicolumn listboxes are temperamental. The easiest way to use them is (as you suggested) to use an array. But, who wants to use an array: just one more variable. You can still use the AddItem method, but it only enters data into the first column, then you must use the List property to add the rest of the columns. Another gotcha: the first row and column are both 0. Here
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ListBox AddItem method (2000)

    Temperamental? Hee, Hee. You said it. I think I was trying to use the .List without both arguments. Even tried column(ugh) to no avail. Think I've got it now though. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •