[RESOLVED] Adding items to listbox from excel
I have a column in excel file contain 100 row I'm trying to import this column into listbox using a button
The problem is that only 48 row is importing from the excel column .
why not all rows inside the column are imported?
here is my code (vb.net form)
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim oExcel As Object = CreateObject("Excel.Application")
Dim oBook As Object = oExcel.Workbooks.Open("C:\Users\User\Desktop\1.xlsx")
Dim oSheet As Object = oBook.Worksheets(1)
Dim i As Integer
Dim cell As String
For i = 0 To AscW(ListBox1.Items.Count.ToString()(i = i + 1)) - 1
'set cell name, e.g. A1, A2, etc
cell = "B" & Convert.ToString(i + 1)
' get cell data from Excel
cell = oSheet.Range(cell).Value
If cell = "" Then
Exit For
Else
ListBox5.Items.Add(cell)
End If
Next
oExcel.Quit()
End Sub
Re: Adding items to listbox from excel
what is the value of this:
Code:
AscW(ListBox1.Items.Count.ToString()(i = i + 1)) - 1
Re: [RESOLVED] Adding items to listbox from excel
What is the purpose of this code and what are you trying to achieve with it?
Code:
For i = 0 To AscW(ListBox1.Items.Count.ToString()(i = i + 1)) - 1
Maybe it's a typo.
/shrugs