问题描述:

I have a code where I'm receiving a "'Range' of Object _Global' failed" error and I'm hoping someone can help as to why. I've looked online and everything seems to advise that I need to specific which sheet the code is referring to, which i've done using With and End With. Please see my code below;

With ThisWorkbook.Worksheets("Tables")

Range(StartingPoint, EndPoint).Copy

End With

However, it doesn't seem to be working. The variables specified above this code are as follows;

Dim ws7 As Worksheet

Set ws7 = ActiveSheet

Dim StartingPoint As Range

Dim EndPoint As Range

Set StartingPoint = Sheets("Tables").Range("C58:R58").Find(ws7.Range("C3"))

If Not StartingPoint Is Nothing Then

Set EndPoint = StartingPoint.Offset(10, 0)

End If

Any help and / or useful reading material would be much appreciated.

Thanks.

网友答案:

Your With statement is not currently doing anything as you haven't qualified the Range call - it needs to be:

With ThisWorkbook.Worksheets("Tables")
.Range(StartingPoint, EndPoint).Copy
End With

Note the full stop in .Range

Also, this assumes those two ranges are on the Tables sheet, or the code will fail.

相关阅读:
Top