Solved

Count number of excel rows +excel 2007 onwards+vb.net 2005

Posted on 2011-03-15
4
973 Views
Last Modified: 2013-11-08
Hi,
I had a previous code to count number of rows in excel 2003 version sheet.But it errors in 2007.Any suggestions


   Public Function GetColumnRowCount(ByVal col As Integer, ByVal xlWorksheet As Object, ByVal xlApp As Object) As Integer
      Try
         Return xlWorksheet.Cells(xlWorksheet.Rows.Count, col).End(-4162).Row
      Catch ex As Exception
         AddMessage(ex.ToString)
      End Try
   End Function

Error:
System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
0
Comment
Question by:RIAS
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 35138534
Change to:

    Return xlWorksheet.UsedRange.Rows.Count
0
 

Author Comment

by:RIAS
ID: 35138601
Cheers I changed that and it works great.
But any suggestion on why it fails on
 Dim oRange As Excel.Range
oRange(1, 1).Value

 Excel.Range  is the interop excel reference.

Same error
System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 35138714
When I want a single cell, I don't bother with a range object:

       strCol = oSheet.Cells(intRow, intCol).Value

But I'm not sure why you're getting your error.
 
0
 

Author Closing Comment

by:RIAS
ID: 35138904
Cheers mate !!!Works like charm
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now