Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current or focused cell value?

Tags:

c#

excel

vsto

When I select a cell, the respective column it gets focused. For I need to get the Column value and Row value (row #) on excel worksheet wherever focus changes.

How can I do the same through code?

How do I get the focused or current cell's column value in VSTO excel using C#?

like image 819
venkat Avatar asked Mar 04 '10 09:03

venkat


People also ask

How to get the current cell value in Excel?

Using CELL() function returns information about the last cell that was changed. So, if we enter a new row or column the CELL() reference will be affected and will not be the current cell's any longer.

How do you find the value of specific cells?

We can get the value of a cell (its content) by using the INDEX Function. The INDEX Function looks up a cell contained within a specified range and returns its value. In the example above, the range specified in the INDEX formula is “A1:J10”, the row is cell “C3” (“3”), and the column is cell “C4” (“5”).


1 Answers

Excel.Range rng = (Excel.Range) this.Application.ActiveCell;

//get the cell value
object cellValue = rng.Value;

//get the row and column details
int row = rng.Row;
int column = rng.Column;

and here's a quick start walkthrough.

like image 150
burnside Avatar answered Sep 21 '22 13:09

burnside