We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do I find the last row in a worksheet

Hi,

I am looking for a simple way to find the last available row in a worksheet. In Excel 97To2003, it is around 65536, while Excel 2007/2010 it is 1048576.

Is there a function or command or something that I can use in a Range call, like:
IRange[] rHide = wsPage.Range[10, 1, xlLastCellRow, 1].Rows;

Thanks,
Mark


3 Replies

JJ Jawahar Jeevanandan J Syncfusion Team July 14, 2011 05:23 AM UTC

Hi Mark,

Thank you very much for using syncfusion products.

To find the last row used in a work sheet we have a property called UsedRange. Through this property we can find the first row, last row, first column and last column used in the work sheet. I have placed the code snippet below for the same.

Code Snippet(C#):

int firstRow = sheet.UsedRange.Row;
int lastRow = sheet.UsedRange.LastRow;
int firstColumn = sheet.UsedRange.Column;
int lastColumn = sheet.UsedRange.LastColumn;

In case of unused rows we can directly access the row through index of the range object. The following code snippet also explains the same.

Code Snipppet (C#):

IRange range = sheet.Range[1, 1, 1048576, 3];
range[1048576, 3].Value = "Syncfusion";

Please let us know if you have any clarifications.

Thanks,
Jawahar.



MO Mark Oudesluys July 14, 2011 06:42 PM UTC

Hi,

Thanks for the response. That is helpful if I want to find the row or column of the last used cell in my worksheet. But what I was hoping for was some kind of function or variable which would return the maximum number of rows or columns available in a worksheet.

As I mentioned, depending on the source sheet version (97To2003 or 2007/2010) the maximum number of rows and columns is different and I was hoping there was a function/variable which would just return that. I was hoping to avoid having to hard code the values into my projects.

Thanks,
Mark



JJ Jawahar Jeevanandan J Syncfusion Team July 15, 2011 12:56 PM UTC

Hi Mark,

Thank you very much for using syncfusion products.

Currently we don't have support for providing maximum no rows or columns through properties or methods as this is known. We don't have any immediate plan to implement this feature. We will get back to you once the feature has been implemented in any of our upcoming releases. I have placed the link below which provides more detailed information about the query posted.

http://office.microsoft.com/en-us/excel/HA100778231033.aspx.

Please let us know if you any clarifications.

Thanks,
Jawahar.


Loader.
Live Chat Icon For mobile
Up arrow icon