在Excel VBA中复制粘贴范围错误

我有一个5列(B到F)和可变数量的填充行的表。 我想将最后3个填充的单元格复制到101行的同一列上的固定范围内。

这是我使用的代码:

Dim WSPL As Worksheet For i = 2 To 6 For j = 7 To 1 Step -1 If Not IsEmpty(WSPL.Cells(j, i).Value) Then WSPL.Range(Cells(j - 2, i), Cells(j, i)).Copy Destination:=WSPL.Cells(101, i) Exit For End If Next j Next i 

这是返回错误:

 Run-time error: 1004 Method 'Range' of object'_Worksheet' failed 

在我上面的代码的第5行。 这段代码有什么问题?

问题是这条线

WSPL.Range(Cells(j - 2, i), Cells(j, i)).Copy Destination:=WSPL.Cells(101, i)

您的单元格对象不完全合格

尝试这个

 With WSPL .Range(.Cells(j - 2, i), .Cells(j, i)).Copy Destination:=.Cells(101, i) End With 

注意单元格之前的DOT?