运行时错误"1004"无法获取WorksheetFunction类的Match属性 [英] Run time error '1004' Unable to get the Match propertyof the WorksheetFunction class

查看:350
本文介绍了运行时错误"1004"无法获取WorksheetFunction类的Match属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的宏中,我有以下代码:

In my macro, I have the following code :

i = Application.WorksheetFunction.Match(str_accrual, Range(Selection, Selection.End(xlToRight)), 0)

其中"str_accrual"是在此行之前捕获的字符串,并且所选范围位于从"A1"到"BH1"的单行中,结果将是一个数字,该数字是该字符串在该范围内的位置已选择.

where 'str_accrual' is a string captured earlier to this line and the Range selected is in a single row say from "A1" to "BH1" and the result will be a number which is the position of that string in that range selected.

运行宏时,出现错误:

运行时错误'1004'无法获取WorksheetFunction类的Match属性

Run time error '1004' Unable to get the Match propertyof the WorksheetFunction class

但是当我使用(F8)键逐行运行宏时,不会出现此错误,但是当我连续运行宏时会出现错误.同样,如果中止该宏并再次运行它,则不会出现错误.

But when I run the macro line by line using (F8) key, I don't get this error but when I run the macro continuously I get the error. Again, if the abort the macro and run it again the error doesn't appear.

推荐答案

我间歇性地收到此错误.原来,这是在我有一个不同的工作表时发生的.

I was getting this error intermittently. Turns out, it happened when I had a different worksheet active.

Range的文档说,

As the docs for Range say,

在不使用对象限定符(句点左侧的对象)的情况下使用时,Range属性将返回活动工作表上的范围.

When it's used without an object qualifier (an object to the left of the period), the Range property returns a range on the active sheet.

因此,要纠正该错误,请添加一个限定符:

So, to fix the error you add a qualifier:

Sheet1.Range

这篇关于运行时错误"1004"无法获取WorksheetFunction类的Match属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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