dimanche 19 avril 2015

How to get a specific cell in a user selected range in Excel using C#

I create my frist Excel Add-In and want to finde specific cells in a range the user select.


I know the Columns in which the values are that I need. So I test it with:



Excel.Range selection = Globals.ThisAddIn.Application.Selection as Excel.Range;
Excel.Range firstValue = selection.Columns["I"].Find("*", Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart,Excel.XlSearchOrder.xlByColumns,Excel.XlSearchDirection.xlNext, false, Type.Missing,Type.Missing);


now I have the first value from column "I"


this works fine when the "selection" the user makes begins in column "A"


If the user select for excample from C2 to H20 the code cant find column "I" I become than an other range, not the "I" column.


I think for him is "I" always "9". When the user select from "C2" to "H20" in the new range is colum "C" = "0" and column "L" = 9 so the code select column "L" even if I write "I" in the code.


Have anyone an idea how can I read the specific column or cell I want inner the selection of the user no matter where the user Begins with his selection?


thank you in advance


Aucun commentaire:

Enregistrer un commentaire