Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am searching some string in the excel worksheet column. This is working perfect.

But, i want to get the row number of the search string in the worksheet...?

What I have tried:

C#
string colToCheck = "C40:C90"
string SearchNo = "ABC-201";
Excel.Range resultRange;
colRange = XLWorkSheet1.Range[colToCheck];//get the range object where you want to search from

                                   resultRange = colRange.Find(

                                                   What: SearchNo,

                                                   LookIn: Excel.XlFindLookIn.xlValues,

                                                   LookAt: Excel.XlLookAt.xlPart,

                                                   SearchOrder: Excel.XlSearchOrder.xlByRows,

                                                   SearchDirection: Excel.XlSearchDirection.xlNext

                                   );
Posted
Updated 3-Jan-19 22:49pm
v2

It returns an Excel.Range object: Range object (Excel) | Microsoft Docs[^]
That has an Address property: Range.Address property (Excel) | Microsoft Docs[^]
Which can give you the RowAbsolute data...
 
Share this answer
 
Comments
Maciej Los 4-Jan-19 4:39am    
5ed!
Excellent...

It is,

int findrow = resultRange.Row;
 
Share this answer
 
Comments
Maciej Los 4-Jan-19 5:16am    
Great, with bit of help of OriginalGriff, you've found it!
gani7787 4-Jan-19 5:42am    
yes. ofcourse.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900