C# – How to get the last filled cell of a given row in Excel

Getting the last row of a given column in Excel with a formula or with VBA is quite a trivial task. It is explained here quite well 🙂

However, when we come to C#, the only “trick” that is provided by the Microsoft.Office.Interop.Excel is getting the last row in general:

The question what happens, if one needs the last cell in a given Excel column, which is of course not the last cell out of all columns. Then simple reverse loop, starting from the last cell in the worksheet until the first cell with value would be of use. Something like this:

Both functions, LastRowPerColumn and LastRowTotal work rather well together, providing the last row per worksheet:

The whole code is in GitHub.com here. Enjoy it!

Tagged with: , , , ,