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#?
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.
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”).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With