Fill a VBA ListBox
Solved
ghalleck
Posted messages
2
Status
Member
-
brunov80 -
brunov80 -
Hello,
I have a low level of VBA (I usually manage), but now I’m stuck with filling a ListBox
I want to fill a ListBox from a search in an Excel file:
the file contains 3 columns: "article code", "date", "need"
(I need to build a small system that displays the dates and needs for the searched article code).
So I perform a search on the article code, and I would like each time I encounter this code, it inserts into my ListBox an additional line containing the date and the need.
here is the beginning of my code:
Private Sub CommandButton1_Click()
nom_fichier = TextBox2.Value & "\" & TextBox1.Value & ".xls"
Workbooks.Open Filename:=nom_fichier
For i = 25 To 10000
'search for the last line
If Not IsEmpty(Cells(i, 1)) Then
a = a + 1
Else
i = 10000
End If
Next
'search for the values of the array that match the search
For j = a To 2 Step -1
If Cells(j, 1) = TextBox3.Value Then
ListBox1.AddItem ....... (must insert on the same line the cells: cells(j, 2) and cells(j,3))
End If
Next
End Sub
***********************************
So I’m stuck with filling my ListBox, and I haven’t found a post with methods (sorry if they exist)
thanks in advance
I have a low level of VBA (I usually manage), but now I’m stuck with filling a ListBox
I want to fill a ListBox from a search in an Excel file:
the file contains 3 columns: "article code", "date", "need"
(I need to build a small system that displays the dates and needs for the searched article code).
So I perform a search on the article code, and I would like each time I encounter this code, it inserts into my ListBox an additional line containing the date and the need.
here is the beginning of my code:
Private Sub CommandButton1_Click()
nom_fichier = TextBox2.Value & "\" & TextBox1.Value & ".xls"
Workbooks.Open Filename:=nom_fichier
For i = 25 To 10000
'search for the last line
If Not IsEmpty(Cells(i, 1)) Then
a = a + 1
Else
i = 10000
End If
Next
'search for the values of the array that match the search
For j = a To 2 Step -1
If Cells(j, 1) = TextBox3.Value Then
ListBox1.AddItem ....... (must insert on the same line the cells: cells(j, 2) and cells(j,3))
End If
Next
End Sub
***********************************
So I’m stuck with filling my ListBox, and I haven’t found a post with methods (sorry if they exist)
thanks in advance
Configuration: Windows XP Internet Explorer 6.0
2 answers
-
Hello,
Have you tried with this:
ListBox1.AddItem Cells(j, 2) & Vbtab & Cells(j,3)
;o)
--
“What is well conceived is clearly stated, and the words to say it come easily.”
Nicolas Boileau -
My God...
My mistake was that I wanted to insert the value (.value) and not the cell ...
Now it works
thank you very much