Results 1 to 3 of 3

Thread: [RESOLVED] Reading only excel cells with information

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED] Reading only excel cells with information

    I am trying to read information from an excel file but I only want to read rows that have information in them. I am currently using the following loop

    VB Code:
    1. For intRow = intStartRow To xlSheet.Cells.Rows.Count
    2.         ' Read each column of each row into the recordset
    3.         rst.AddNew
    4.         rst("LastName") = xlSheet.Cells(intRow, intCol + 1).Value
    5.         rst("FirstName") = xlSheet.Cells(intRow, intCol + 2).Value
    6.         rst("FullName") = xlSheet.Cells(intRow, intCol + 3).Value
    7.         rst("BusinessPhone") = FormatPhone(xlSheet.Cells(intRow, intCol + 4).Value)
    8.         rst("MobilePhone") = FormatPhone(xlSheet.Cells(intRow, intCol + 5).Value)
    9.         rst("Pager") = FormatPhone(xlSheet.Cells(intRow, intCol + 6).Value)
    10.         rst("Email") = xlSheet.Cells(intRow, intCol + 7).Value
    11.        
    12.         rst.Update ' Update temporary table
    13.        
    14.         intCol = 1 ' Move back to the first column
    15.     Next intRow

    However xlSheet.Cells.Rows.Count returns all the rows in the excel sheet when there are only 95 rows that have actual data in them. How do I just read the rows that have data in them?

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Reading only excel cells with information

    See the "Excel Tutorial" link in my signature for a variety of ways to detect the used rows (including UsedRange).

  3. #3

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Reading only excel cells with information

    Thanks Si

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

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