OK. Try this macro:
Public Sub PopulateData()
Dim oneSheet As Worksheet
Dim twoSheet As Worksheet
Dim lastRow As Long
Dim thisRow As Long
Dim firstRow As Long
Dim thisCol As Long
Dim foundRow
Dim foundCol
Application.ScreenUpdating = False
Set oneSheet = Worksheets("Sheet1")
Set twoSheet = Worksheets("Sheet2")
firstRow = 0
lastRow = oneSheet.Cells(oneSheet.Rows.Count, "A").End(xlUp).Row
For thisRow = 2 To lastRow + 1
If oneSheet.Cells(thisRow, "A").Value <> oneSheet.Cells(thisRow - 1, "A").Value _
Or oneSheet.Cells(thisRow, "B").Value <> oneSheet.Cells(thisRow - 1, "B").Value _
Or oneSheet.Cells(thisRow, "C").Value <> oneSheet.Cells(thisRow - 1, "C").Value Then
If firstRow <> 0 Then
foundRow = Application.Match(oneSheet.Cells(firstRow, "A").Value, twoSheet.Range("A:A"), 0)
foundCol = Application.Match(oneSheet.Cells(firstRow, "C").Value, twoSheet.Range("1:1"), 0)
If Not (IsError(foundRow) Or IsError(foundCol)) Then
thisCol = oneSheet.Cells(thisRow, "B").Value - 2012
If oneSheet.Cells(thisRow, "C").Value = "B" Then thisCol = thisCol + 8
twoSheet.Cells(foundRow, foundCol + oneSheet.Cells(firstRow, "B").Value - 2014).Value = Application.WorksheetFunction.Average(oneSheet.Cells(firstRow, "D").Resize(thisRow - firstRow))
End If
End If
firstRow = thisRow
End If
Next thisRow
Application.ScreenUpdating = True
End Sub
WBD
Bookmarks