Click here to Skip to main content
15,914,795 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,
I quickly came across another problem while trying to find a value in Excel. I use the following code. (All declaration and assignment have been done prior to this)
And after execution the "FoundLoc" is null.

Excel.Worksheet ExcelSheet = (Excel.Worksheet)ExcelWB.Sheets["Sheet1"];
Excel.Range Foundloc;

Foundloc = ExcelSheet.Cells.Find("test",  MissingObject, Excel.XlFindLookIn.xlValues,  Excel.XlLookAt.xlWhole,  Excel.XlSearchOrder.xlByRows,  Excel.XlSearchDirection.xlNext,  false,  false,  false);


I suspect that my excel file has formulas which result in values and filters. But i am not sure if it is because of this.
Could any only please help me out whith this.

[edit]Tags only = OriginalGriff[/edit]
Posted
Updated 29-May-11 21:47pm
v2

I am able to search using the your code. You might want to look at two things:
1. "test" is part/whole of the cell content. If it is just a part, change "Excel.XlLookAt.xlWhole" to "Excel.XlLookAt.xlPart".
2. What is the value of "MissingObject".
 
Share this answer
 
Comments
asjadazeez 30-May-11 5:13am    
Well i guess i realised this. Thanks for you info. It was indeed because i was using Excel.XlLookAt.xlWhole instead of xlpart. Now it works fine. Mistake overlooked !.
The above code works for me (Excel 11.0 and VS 2005/2008).

Things you could try:

a) use MissingObject instead of the last false (the search format parameter will only select cells that match the specified format - I'm not sure what false equates to as a search format, but it is unlikely to be what you want)

b) Excel.XlLookAt.xlPart instead of Excel.XlLookAt.xlWhole (makes sure that there aren't any nasty leading/trailing white space - I've been hit by that one a few times)

c) Specify the after parameter as a particular cell (say "A1")

If these don't work then without your actual Excel file then I'm not sure I can help you further, although a couple of tips:

1. Work on a simplified copy of your Excel file - might help work out what is special about your file/search text

2. Open your file in Excel and do the search manually - check for anything special that you need to set to get the search to work
 
Share this answer
 
Comments
asjadazeez 30-May-11 5:18am    
Thanks for the detailed description. I got it. It was due to point b.

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