Worksheet.Find函数似乎不起作用? [英] The Worksheet.Find function does not seem to work ?

查看:139
本文介绍了Worksheet.Find函数似乎不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
在尝试在Excel中查找值时,我很快遇到了另一个问题.我使用以下代码. (所有声明和赋值均已在此之前完成)
执行后,"FoundLoc"为空.

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);



我怀疑我的excel文件具有导致值和过滤器的公式.但是我不确定是否是因为这个原因. 只能请帮我吗.

[edit]仅标记= OriginalGriff [/edit]



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]

推荐答案

我能够使用您的代码进行搜索.您可能要看两件事:
1.测试"是单元格内容的一部分/全部.如果只是一部分,请将"Excel.XlLookAt.xlWhole"更改为"Excel.XlLookAt.xlPart".
2."MissingObject"的值是什么.
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".


上面的代码对我有用(Excel 11.0和VS 2005/2008).
您可以尝试的操作:

a)使用MissingObject而不是最后一个false(搜索格式参数将仅选择与指定格式匹配的单元格-我不确定什么false等于搜索格式,但不太可能是您想要的)

b)Excel.XlLookAt.xlPart而不是Excel.XlLookAt.xlWhole(确保没有任何令人讨厌的前导/尾随空格-我被这几次打中了)

c)将 after 参数指定为特定的单元格(例如"A1")

如果这些方法不起作用,那么没有您的实际Excel文件,那么我不确定可以进一步帮助您,尽管有一些技巧:

1.处理Excel文件的简化副本-可能有助于确定文件/搜索文本的特殊之处

2.在Excel中打开文件并手动进行搜索-检查是否需要设置特殊内容才能使搜索生效
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


这篇关于Worksheet.Find函数似乎不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆