在VBA Excel中查找范围 [英] Range.Find in VBA Excel

查看:236
本文介绍了在VBA Excel中查找范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下指令在Excel工作表中执行查找":

I'm trying to perform a "find" in a Excel sheet with this instruction:

Set Found = Columns(2).Find(What:=value_to_find, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

但是出现错误运行时错误'13':类型不匹配".

but I get the error "Run-time error '13': Type mismatch".

如果我使用Range("A1:H1")而不是Columns(2),则不会出现任何错误,但我认为它们都属于Range.

If I use Range("A1:H1") instead of Columns(2) I don't get any errors, but I think they are both type Range.

我的目标是使用Range变量,在脚本开始时,我会根据用户的选择对它进行评估.

My aim is use a Range variable, at the start of the script I valorize it according to the user's choice.

推荐答案

[已解决] 非常感谢大家,我在拉尔夫的支持下解决了我的问题.

[RESOLVED] Many Thanks everyone, I resolved my question with the Ralph's support.

在您的代码中找到的变量必须是variant类型.因此,如果您明确将Dim Found设置为变体,则您的代码应该可以工作.

The variable Found (in your code) must be of type variant. So, if you explicitly set Dim Found as variant then your code should work.

这篇关于在VBA Excel中查找范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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