I'm using a macro to copy data from one worksheet to another. It has always worked perfectly until today. For some reason the date in the destination workbook is 1 day and 4 years behind the original.
It's automatically doing something like this =DATE(YEAR(C2)-4,MONTH(C2),DAY(C2)-1)
Sub CopyToDestinationWorkbook()
Dim ws As Worksheet, ws2 As Worksheet, x As Range, i As Long, y As Long
Set ws = Workbooks("Original Workbook.xlsm").Sheets("Sheet1")
Set ws2 = Workbooks("Destination Workbook.xlsm").Sheets("Import")
With ws
For i = 1 To .UsedRange.Columns.Count
Set x = ws2.Rows(2).Find(ws.Cells(1, i).Value, LookIn:=xlValues, lookat:=xlWhole)
If Not x Is Nothing Then
y = .Cells(Rows.Count, i).End(3).Row
.Range(.Cells(2, i), .Cells(y, i)).Copy ws2.Cells(3, x.Column)
End If
Set x = Nothing
Next i
End With
End Sub
I've tested different workbooks, and different dates, as well as different date formats. I've even tried it on two different computers. I cannot figure this out. Any ideas?
Bookmarks