Mathias Brandewinder on .NET, F#, VSTO and Excel development, and quantitative analysis / machine learning.
by Mathias 6. January 2009 19:05

I am currently working on an application which requires reading the contents of an Excel worksheet into a 2-dimensional array. I want to avoid loading the entire contents of the worksheet, and want to read only the upper-left quadrant, and leave out all the empty cells on the left and the bottom of the sheet. Problem is, how do you find out the last cell that contains something, that is, the cell such that no cell below it or on its right has content?

Everything Google turned up looked pretty nasty - either brute force, or acrobatic usage of Excel functions, until I stumbled across this little gem:

var lastCell = xlWorksheet.Cells.SpecialCells(

You learn everyday.


10/8/2009 4:46:23 PM #


Read the contents of a worksheet with C#

Read the contents of a worksheet with C#

Clear Lines Blog | Reply

8/20/2012 1:13:37 AM #


in your case you could simply have used:

Excel.Worksheet.UsedRange property. This retuns the range that has data in it.
Instead of finding lastCell and then assembling a Range from row and column.

Niels Netherlands | Reply

8/20/2012 1:15:30 AM #


You could have used

Excel.Worksheet.UsedRange property.

Instead of finding lastCell and the assembling a Range from it.

Niels Netherlands | Reply

12/19/2016 11:07:35 PM #


Pingback from

anabolic steroids | Reply

Add comment

  Country flag

  • Comment
  • Preview


Comment RSS