Hi all,
When using the following module (and different versions of - there's a lot of with statements in there as I've been troubleshooting so its a mess, sorry)...
the following code in a sub that runs a LOT later fails
the starred ** line specifically with the error message "method range of object worksheet failed"
However... If I change the sub doing the copy pasting to the folllowing
everything works perfectly. Why is this? What's going on with that paste method that screws up some code over 7 subs later? also note that the line that fails works without "ws1." unless the copy sub also runs
I'm a bit baffled by this!
Thanks for any help!
When using the following module (and different versions of - there's a lot of with statements in there as I've been troubleshooting so its a mess, sorry)...
VBA Code:
Sub ImportHSR()
Dim wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Set wb1 = Workbooks("workbook1.xlsm")
Set wb2 = Workbooks.Open(FileName:="...")
Set ws1 = wb1.Worksheets(7)
Set ws2 = wb2.Worksheets("sheet1")
With wb2
ws2.Range(("A2:E2"), ws2.Range("A2:E2").End(xlDown)).Copy
End With
With wb1
ws1.Range("C2").PasteSpecial Paste:=xlPasteValues
ws1.Columns("D:F").EntireColumn.Delete
End With
With wb2
.Close
End With
End Sub
the following code in a sub that runs a LOT later fails
VBA Code:
Set ws1 = Worksheets(1)
With ws1
For Each Cell In ws1.Range(Cells(searchRow, 3), Cells(searchRow, lastCol)) **
the starred ** line specifically with the error message "method range of object worksheet failed"
However... If I change the sub doing the copy pasting to the folllowing
VBA Code:
Sub ImportHSR()
Dim wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Set wb1 = Workbooks("workbook1.xlsm")
Set wb2 = Workbooks.Open(FileName:="...")
Set ws1 = wb1.Worksheets(7)
Set ws2 = wb2.Worksheets("sheet1")
With wb2
ws2.Range(("A2:E2"), ws2.Range("A2:E2").End(xlDown)).Copy Destination:=ws1.Range("C2")
'.Close
End With
ws1.Range("C2").PasteSpecial Paste:=xlPasteValues
End Sub
everything works perfectly. Why is this? What's going on with that paste method that screws up some code over 7 subs later? also note that the line that fails works without "ws1." unless the copy sub also runs
I'm a bit baffled by this!
Thanks for any help!