Skip to content

Instantly share code, notes, and snippets.

@gregphillips03
Created November 17, 2017 19:18
Show Gist options
  • Save gregphillips03/ba20e23f727dc093de07fda2896e3892 to your computer and use it in GitHub Desktop.
Save gregphillips03/ba20e23f727dc093de07fda2896e3892 to your computer and use it in GitHub Desktop.
Sub NewTable()
Set Table = Sheet1.[a2:d4]
With Application
Record = .Transpose(.Index(Table, , 1))
FirstDate = .Transpose(.Index(Table, , 2))
LastDate = .Transpose(.Index(Table, , 3))
Count = .Transpose(.Index(Table, , 4))
Dates = .Evaluate("row(" & .Min(FirstDate) & ":" & .Max(LastDate) & ")")
Values = .PV(, Count, .PV(, .GeStep(Dates, FirstDate), .GeStep(LastDate, Dates)))
Sum = .MMult(Values, .Power(.Transpose(Record), 0))
End With
Sheet1.[F1].Offset(, 1).Resize(, UBound(Values, 2)) = Record
Sheet1.[F2].Resize(UBound(Dates)) = Dates
Sheet1.[G2].Resize(UBound(Values), UBound(Values, 2)) = Values
Sheet1.[G2].Offset(, UBound(Values, 2)).Resize(UBound(Dates)) = Sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment