Chethan Chethan - 1 year ago 100
C# Question

How to Select all the cells in a worksheet in Excel.Range object of c#?

I am trying to select all the cells in an Excel sheet in the

object of C# for applying auto fit, border etc. I have some merged cells within the sheets.

Is there any simple trick to do so?

Answer Source

Taken from here, this will select all cells in the worksheet:

lastCol = ActiveSheet.Range("a1").End(xlToRight).Column
lastRow = ActiveSheet.Cells(65536, lastCol).End(xlUp).Row
ActiveSheet.Range("a1", ActiveSheet.Cells(lastRow, lastCol)).Select
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download