Hi all,
I've used the following code a few hundred times for the last few months (and its worked perfectly) - I've seen this error about twice.
"error 1004 Method range of object_worksheet failed" - error on *** line
I do not understand why its happy to work 98% of the time - I'm wondering if it has anything to do with somebody else being in the workbook I'm accessing at the time, but I'm sure that's happened before and its been fine. There's no restrictions on the workbook aside from location (which I have access to).
From what I can tell, its opening wb2 absolutely fine, but its opening to the wrong sheet - even though the name of the sheet matches perfectly - and trying to copy an area that doesn't make much sense. But *why* is it only giving me this error a couple of times out of months of usage? It worked perfectly yesterday and for weeks previously, but not at all today no matter how many times I run it.
Is there a method I can use that *should* be more reliable?
Thanks all
I've used the following code a few hundred times for the last few months (and its worked perfectly) - I've seen this error about twice.
"error 1004 Method range of object_worksheet failed" - error on *** line
VBA Code:
Dim wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Set wb1 = Workbooks("MyWorkbook.xlsm")
Set wb2 = Workbooks.Open(FileName:="MyOtherWorkbookURL.xlsx")
Set ws1 = wb1.Worksheets(7)
Set ws2 = wb2.Worksheets("MyOtherWorkbookSheet")
ws2.Range(("A2:E2"), Range("A2:E2").End(xlDown)).Copy ***
ws1.Range("C2").PasteSpecial Paste:=xlPasteValues
ws1.Columns("D:F").EntireColumn.Delete
wb2.Close
I do not understand why its happy to work 98% of the time - I'm wondering if it has anything to do with somebody else being in the workbook I'm accessing at the time, but I'm sure that's happened before and its been fine. There's no restrictions on the workbook aside from location (which I have access to).
From what I can tell, its opening wb2 absolutely fine, but its opening to the wrong sheet - even though the name of the sheet matches perfectly - and trying to copy an area that doesn't make much sense. But *why* is it only giving me this error a couple of times out of months of usage? It worked perfectly yesterday and for weeks previously, but not at all today no matter how many times I run it.
Is there a method I can use that *should* be more reliable?
Thanks all