Here, try this:
Sub transfer_date()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim i As Integer
Dim j As Integer
Dim LastCol As Integer
Dim LastRow As Integer
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
LastCol = ws1.Range("IV1").End(xlToLeft).Column
For i = 0 To LastCol
If ws1.Range("A1").Offset(0, i).Value = "DATE" Then
LastRow = ws1.Range("A1").Offset(65535, i).End(xlUp).Row
For j = 1 To LastRow
ws1.Range("A1").Offset(j, i + 2).Value = Application.SumIf(ws2.Range("A1:A65535"), ws1.Range("A1").Offset(j, i).Value, ws2.Range("B1:B65536"))
Next j
End If
Next i
End Sub
Bookmarks