Sub abc()
Const shMaster As String = "MasterData"
Const shResults As String = "ResultsPage"
Dim i As Long, ii As Long, ptr As Long, icol As Long
Dim a, x, y
With Worksheets(shMaster)
a = .Range("a1").CurrentRegion
End With
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(a)
x = Join(Array(a(i, 1), a(i, 2), a(i, 3)), ",")
If Not .Exists(x) Then
.Item(x) = Join(Array(a(i, 6), a(i, 7), a(i, 8), a(i, 9), a(i, 10)), ",")
Else
.Item(x) = .Item(x) & "," & Join(Array(a(i, 6), a(i, 7), a(i, 8), a(i, 9), a(i, 10)), ",")
End If
Next
a = .Items
x = .Keys
End With
icol = 4
ptr = 5
With Worksheets(shResults)
.Cells.Clear
For i = LBound(x) To UBound(x)
.Cells(1, icol).Resize(3) = WorksheetFunction.Transpose(Split(x(i), ","))
With .Cells(4, icol - 2).Resize(, 6)
.Value = Array("production Date", "gas", "oil", "water", "BOE", "Cumm BOE")
.Borders.LineStyle = xlContinuous
End With
y = Split(a(i), ",")
For ii = LBound(y) To UBound(y) Step 5
With .Cells(ptr, icol - 2).Resize(, 6)
.Value = Array(y(ii), y(ii + 1), y(ii + 2), y(ii + 3), y(ii + 4), "")
.Borders.LineStyle = xlContinuous
End With
With .Cells(ptr, icol - 2) '<===== Add formulas to Cumm BOE
If ptr = 5 Then
.Offset(, 5).Value = "=" & .Offset(, 4).Address
Else
.Offset(, 5).Value = "=" & .Offset(-1, 5).Address & "+" & .Offset(, 4).Address
End If
End With
ptr = ptr + 1
Next
ptr = 5
icol = icol + 7
Next
End With
End Sub
Bookmarks