Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-15
4
Medium Priority
?
988 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

618 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