Results 1 to 3 of 3

Thread: [RESOLVED] Adding items to listbox from excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2015
    Posts
    3

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Adding items to listbox from excel

    what is the value of this:

    Code:
    AscW(ListBox1.Items.Count.ToString()(i = i + 1)) - 1

  3. #3
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    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
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width