外部范围抛出错误 400

External range throwing error 400

我正在为某件事而苦苦挣扎:

我需要的代码是:

Set myrange = WS.Range(Cells(1, 1), Cells(10, 10))

但这会导致 400 错误。

奇怪的是,两条线中的任何一条都可以正常工作:

Set myrange = WS.Range("a1:b2")

Set myrange = Range(Cells(1, 1), Cells(10, 10))

因此,如果我将外部 sheet 引用 (WS) 与使用单元格的范围引用相结合,我似乎只会遇到麻烦。

这可能是什么问题?

尝试在代码的每个部分定义 sheet:

Set myrange = WS.Range(WS.Cells(1, 1), WS.Cells(10, 10))
'or
With WS
Set myrange = .Range(.Cells(1, 1), .Cells(10, 10))

无论是使用 Range 对象还是 Cells 对象调用的每个 Range 都需要定义 sheet.