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

excel vba select range from active cell
excel vba select cell value
vba select all cells with data
excel vba select range using offset
c# excel select range of cells
worksheet range(cells)
excel vba select range by row and column number
excel vba selection

I am trying to select all the cells in an Excel sheet in the Excel.Range 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?


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

Worksheet.Range Property (Microsoft.Office.Tools.Excel), Gets a Range object that represents a cell or a range of cells. C# Copy. public Microsoft.Office.Tools.Excel.Worksheet_RangeType Range { get; }  C# (CSharp) Microsoft.Office.Interop.Excel Range.Select - 3 examples found. These are the top rated real world C# (CSharp) examples of Microsoft.Office.Interop.Excel.Range.Select extracted from open source projects. You can rate examples to help us improve the quality of examples.


public void refreshSheetColumsSize(Worksheet ws)
 {
    ws.get_Range("a1").EntireRow.EntireColumn.Select();         
 }

Excel Cells & Ranges - Selecting Cells, cannot select a cell unless that particular worksheet is displayed/active ?? second Object parameter that can be set to True to indicate if you want Excel to scroll The UsedRange is the range of all non-empty cells. Range("A;A,C;C,E;​E"). Gets a Range object that represents a cell or a range of cells. A Range that represents a cell or a range of cells. The following code example demonstrates different ways to use the Range property to access a single cell or multiple cells. This example is for an application-level add-in. private void CompareRangeUsage() { Worksheet


Excel.Range theRange = (Excel.Range)CurrentSheet.UsedRange;

In this example, CurrentSheet is the variable where you have stored the sheet you are currently using.

Pro C# 5.0 and the .NET 4.5 Framework, COM interop Without C# Dynamic Data Now, if you were to select the Microsoft. Office. ((Excel. Range)workSheet. Cells[row, "A"]).Value2 = c.Make; ((Excel. Gets a Range object that represents all the cells on the worksheet (not just the cells that are currently in use). Property Value. A Range object that represents all the cells on the worksheet (not just the cells that are currently in use). Applies to.


Officially, Excel.Worksheet.UsedRange.Rows and Excel.Worksheet.UsedRange.Columns.

In practice, it's buggy, you have to subtract the start row and column. The closest-to-correct answer is:

   Public ReadOnly Property LastColumn() As Integer
        Get
            Return ExcelWorksheet.UsedRange.Columns.Count + _
                   ExcelWorksheet.UsedRange.Column - 1
        End Get
    End Property
    Public ReadOnly Property LastRow() As Integer
        Get
            Return ExcelWorksheet.UsedRange.Rows.Count + _
                   ExcelWorksheet.UsedRange.Row - 1
        End Get
    End Property

This returns at least all the used cells, sometimes a little more. The 'little more' can be due to blank cells (rather than empty), and other random things. Form the research I did, this is the best that can be done.

If you really want to select everything then

ExcelWorksheet.Activate()
ExcelWorksheet.Cells.Select()

Pro C# 2010 and the .NET 4 Platform, Now, if you were to select the Microsoft. the benefit of optional/named parameters, and must explicitly marked all missing Missing); // Must cast Object as _Worksheet! ((Excel.Range)workSheet.Cells[row, "A"]).Value2 = c.Make; ((​Excel. To select all cells on a worksheet, use one of the following methods: Click the Select All button. Press CTRL+A. Note If the worksheet contains data, and the active cell is above or to the right of the data, pressing CTRL+A selects the current region. Pressing CTRL+A a second time selects the entire worksheet.


I've not done any excel development for a while (Excel 2003) but I always found that recording a macro while performing the tasks I was wanting to implement in code have sufficient pointers to help.

In this case, selecting all cells and autofitting gives the code:

Sub Macro1()
    Cells.Select
    Cells.EntireColumn.AutoFit
End Sub

which I would imagine would roughly translate to:

((Microsoft.Office.Interop.Excel.Range)_sheet.Cells.Select()).AutoFit();

where _sheet is the instance of the Worksheet you're using. (untested)

Pro C# 7: With .NET and .NET Core, Now, if you were to select the Microsoft. benefit of optional/named parameters and would have to explicitly mark all missing Missing); // Must cast Object as _Worksheet! ((Excel.Range)workSheet.Cells[row, "A"]).Value2 = c.Make; ((​Excel. An Excel cell or range of cells can be referenced by using either names or indexes. If using indexes, you can specify absolute or relative position. The following example shows various techniques for referencing ExcelCell and CellRange objects in C# and VB.NET, which can be used in GemBox.Spreadsheet library.


Microsoft Office 2007-Illustrated Introductory, Windows XP Edition, TROUBLE Embedding an Excel Worksheet in PowerPoint You can use the Object command to embed Excel objects such as worksheets and charts into both in the upper-left corner of the embedded worksheet to select all the worksheet cells, Enter the labels and values in the range A1:D4 as shown in Figure C-5, then  C# (CSharp) Worksheet.get_Range - 30 examples found. These are the top rated real world C# (CSharp) examples of Worksheet.get_Range extracted from open source projects. You can rate examples to help us improve the quality of examples.


Select all cells on a worksheet - Excel, Pressing CTRL+A a second time selects the entire worksheet. Tip If you want to select all cells in the active range, press CTRL+SHIFT+*. Using this property without an object qualifier returns a Range object that represents all the cells on the active worksheet. Example. This example sets the font size for cell C5 on Sheet1 of the active workbook to 14 points. Worksheets("Sheet1").Cells(5, 3).Font.Size = 14 This example clears the formula in cell one on Sheet1 of the active


VBA Select Range / Cells, VBA allows you to select a cell, ranges or all the cells in the worksheet. You can You can select a group of cells in a worksheet using the Select method and the Range object. The following code will select column C in your worksheet:  How to Select a Cell on the Active Worksheet. To select cell D5 on the active worksheet, you can use either of the following examples: ActiveSheet.Cells(5, 4).Select -or- ActiveSheet.Range("D5").Select How to Select a Cell on Another Worksheet in the Same Workbook. To select cell E6 on another worksheet in the same workbook, you can use either