Hello Experts!
I am attempting to write a macro that will open a workbook, grab data based on the last date updated in the current workbook and append to running data in current workbook. The code I have written will successfully open the required workbook and does copy over data but only one row. It is copying it into row 1 over top of my header and it is not appending the data to keep a running record.
WB1 is my current workbook where I want the data to append
WB2 is the workbook that has the data that I want to copy over.
Sub CopyCardData()
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim cCell As Range
Dim MaxDate As Date
Dim I As Long, MaxRow1 As Long, MaxRow2 As Long
Set WB1 = Workbooks("WebStats_Data_Combine.xlsm")
Set WS1 = WB1.Sheets("Append_Data")
MaxRow1 = WS1.Range("A" & WS1.Rows.Count).End(xlUp).Row
MaxDate = Application.WorksheetFunction.Max(WS1.UsedRange)
Set WB2 = Workbooks.Open("**") `workbook location
Set WS2 = Sheets("Card")
MaxRow2 = WS2.Range("A" & WS2.Rows.Count).End(xlUp).Row
For I = 2 To MaxRow2
If WS2.Cells(I, "A") > MaxDate Then
WS2.Cells(I, "A").EntireRow.Copy WS1.Cells(MaxRow1, "A")
MaxRow1 = MaxRow + 1
End If
Next I
MsgBox "Transfer Done."
Workbooks("FraudCardIntervals.xlsx").Close
End Sub
I really appreciate any help that you can give me! Thank you in advance.
Jbeets
Bookmarks