Hi
I have the below code to copy data from one workbook to another but keep getting a subscript out of range error on the line...
Both workbooks are open and I've checked the file name is correct etc. What could the issue be?
Sub Export_data()
Dim ws As Worksheet, wb As Workbook
Set ws = Sheets("Triage")
Set wb = Workbooks("2019_-_Couriersheet_-_copy.xlsx").Worksheets("Triage2")
Dim lr As Long, lrw As Long, lc As Long
Application.ScreenUpdating = False
lrw = ws.Range("A" &Rows.Count).End(xlUp).Row
If lrw <> 1 Then
lc= ws.Cells(1, Columns.Count).End(xlToLeft).Column
lr= wb.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range(ws.Cells(2, 1), ws.Cells(lrw, lc)).Copy
wb.Range("A" & lr).PasteSpecial xlPasteValues
ws.Range(ws.Cells(2, 1), ws.Cells(lrw, lc)).EntireRow.Delete
End If
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox" Exported ! "
End Sub
I have the below code to copy data from one workbook to another but keep getting a subscript out of range error on the line...
Set wb = Workbooks("2019_-_Couriersheet_-_copy.xlsx").Worksheets("Triage2")
Both workbooks are open and I've checked the file name is correct etc. What could the issue be?
Sub Export_data()
Dim ws As Worksheet, wb As Workbook
Set ws = Sheets("Triage")
Set wb = Workbooks("2019_-_Couriersheet_-_copy.xlsx").Worksheets("Triage2")
Dim lr As Long, lrw As Long, lc As Long
Application.ScreenUpdating = False
lrw = ws.Range("A" &Rows.Count).End(xlUp).Row
If lrw <> 1 Then
lc= ws.Cells(1, Columns.Count).End(xlToLeft).Column
lr= wb.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range(ws.Cells(2, 1), ws.Cells(lrw, lc)).Copy
wb.Range("A" & lr).PasteSpecial xlPasteValues
ws.Range(ws.Cells(2, 1), ws.Cells(lrw, lc)).EntireRow.Delete
End If
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox" Exported ! "
End Sub