"Method 'Range' of object '_Worksheet' failed" 错误信息

"Method 'Range' of object '_Worksheet' failed" error message

我已经尝试了底部链接的问题中建议的代码,但在线上出现错误:

Set getNthColumn = Range(startCell, endCell)

错误是

Method 'Range' of object '_Worksheet' failed

此代码应该设置公式为 VLOOKUP 的范围单元格的颜色格式。

感谢所有帮助。

Vlookup to copy color of a cell - Excel VBA

显然你把代码放到了作品sheet的代码模块中。

在这种情况下,Range() 解析为该作品的 Worksheet.Range()sheet。如果 startCellendCell 属于不同的 sheet 你会得到一个错误。

如果您将代码放在普通模块中,如 OP specifically requestedRange() 将意味着 Application.Range(),这将正确构建您的范围。

您可以通过显式使用 Application.Range(startCell, endCell).

来消除这种歧义