Hello,
I have this code to copy data from A2:AQ in one workbook to another but it is not working. I would like the code to coy all the data from workbook ITT to the last empty row in CW. Can I please have your help on this?
I have this code to copy data from A2:AQ in one workbook to another but it is not working. I would like the code to coy all the data from workbook ITT to the last empty row in CW. Can I please have your help on this?
VBA Code:
Sub Button3_Click()
'Find the last used row in both sheets and copy and paste data below existing data.
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
'Set variables for copy and destination sheets
Set wsCopy = Workbooks("ITT.xlsm").Worksheets("FormattedData")
Set wsDest = Workbooks(" CW.xlsx").Worksheets("Sheet")
'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
'3. Copy & Paste Data
wsCopy.Range("A2:AQ" & lCopyLastRow).Copy _
wsDest.Range("A" & lDestLastRow)
wsDest.Activate
Option Explicit
Sub OpenWorkbook()
'Open a workbook
Workbooks.Open "C:\DS\Data\Report\CW.xlsx"
End Sub
Sub CloseWorkbook()
'Close a workbook
Workbooks("CW.xlsx").Close SaveChanges:=True
End Sub