Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to focus or select a cell in Excel

How to focus a cell in Excel VSTO using C# or to select first cell using C# in VSTO?

like image 998
venkat Avatar asked Mar 25 '10 08:03

venkat


People also ask

How do I focus one cell in Excel?

To switch focus in Excel, simply press the F2 key on your keyboard. This will instantly move the focus to the cell or range that you have selected. You can then use the arrow keys on your keyboard to move around within that cell or range.

How do you select active cell?

Use the Active Cell PropertyType the keyword “ActiveCell”. Type a dot (.) to get the list properties and methods. Select the property or method that you want to use. Run the code to perform the activity to the active cell.

How do you select cells in Excel without dragging?

To select a range of cells without dragging the mouse: Click in the cell which is to be one corner of the range of cells. Move the mouse to the opposite corner of the range of cells. Hold down the Shift key and click.


2 Answers

Here is one way:

Excel.Worksheet activeSheet = ThisAddIn.ExcelApplication.ActiveSheet;
var range = activeSheet.get_Range("A1", "A1");
range.Select();

ThisAddIn is the name of my test project.

like image 188
Mikael Svenson Avatar answered Sep 28 '22 09:09

Mikael Svenson


To select the A2 cell, for example:

Excel.Worksheet Worksheet = excel.ActiveWorkbook.ActiveSheet;
Worksheet.get_Range([1,2], System.Reflection.Missing.Value).Select();
like image 23
praveena Avatar answered Sep 28 '22 07:09

praveena