Is there a way to find the last used cell?

Hi,

I am trying to find a simple way of finding the last column with data in it.

In Excel VBA, the command Worksheet(sheetname).SpecialCells(xlCellTypeLastCell) will get the last cell used in the worksheet. Is there an equivalent command in Syncfusion XlsIO?

Thanks,
Mark

1 Reply

SB Sathish Babu R Syncfusion Team August 20, 2010 05:10 AM UTC

Hi Mark ,

Thank you for your interest in Syncfusion products.

In our XlsIO, It is possible to get the last cell in the used range with the below code snippet. Also we have attached sample for your reference. Could you please try the same and let us know if this helps you.

Code Snippet:

C#
IRange usedRange = sheet.UsedRange;
IRange lastCell = usedRange[usedRange.LastRow, usedRange.LastColumn];
lastCell.Text = "Last cell";

VB.Net
Dim usedRange as IRange = sheet.UsedRange
Dim lastCell as IRange
lastCell = usedRange(usedRange.LastRow, usedRange.LastColumn)
lastCell.Text = "Last cell"

Sample:
http://help.syncfusion.com/samples/xlsio.windows/supports/F96088-%20Find%20last%20cell.zip

Please let us know if you have any queries.

Regards,
Sathish

Loader.
Up arrow icon