Solved

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

Posted on 2011-03-15
4
984 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 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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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