Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Const TargetSheetName = "New Data Consolidation"
- Const MonthsBackInTime = 12
- Const StartingSheet = 5
- Const EndingSheet = 22
- Public Sub PrepareConsolidation()
- '---------------------------------------------------------------------------------------
- ' Procedure : PrepareConsolidation
- ' Author : L.B.
- ' Date : 20/08/2013
- ' Purpose : Consolidate the main data from the single mastertrusts
- '---------------------------------------------------------------------------------------
- Application.ScreenUpdating = False
- Dim FieldNumber As Integer
- Dim FieldTag As String
- Dim i As Long, j As Long
- Dim FieldRow As Long
- For i = 1 To MonthsBackInTime
- With Sheets(TargetSheetName).Range("A1").Offset(0, i)
- .Value = Application.WorksheetFunction.EoMonth(Date, -(i + 1)) + 1
- .NumberFormat = "mmm-yy"
- End With
- Next i
- '---------------------------------------------------------------------------------------
- ' 90+ Arrears
- '---------------------------------------------------------------------------------------
- FieldNumber = 0
- FieldTag = "3m"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "90+ Arrears"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "0.00%"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' CPR
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "cpr"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "CPR"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "0.00%"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' AAA CE
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "aaa"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "Most senior CE"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "0.00%"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' Reserve Fund
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "res"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "Reserve Fund"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "0.00%"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' Excess Spread
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "excess"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "Excess Spread"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "0.00%"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' Size
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "size"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "Mortgage Amount outstanding"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "#,###"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' Loss %
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "loss"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "Loss Rate"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "0.00%"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' WALTV
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "ltv"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "WA LTV"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "0.00%"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- '---------------------------------------------------------------------------------------
- ' WA Size
- '---------------------------------------------------------------------------------------
- FieldNumber = FieldNumber + 1
- FieldTag = "loan"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Value = "WA Mortgage Size"
- Sheets(TargetSheetName).Range("A2").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Font.Italic = True
- On Error Resume Next
- For i = StartingSheet To EndingSheet
- FieldRow = -1
- FieldRow = Sheets(i).Range("B:B").Find(What:=FieldTag).Row
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Offset(i - StartingSheet, 0)
- .Value = Sheets(i).Name
- If (FieldRow > 0) Then
- For j = 1 To MonthsBackInTime
- .Offset(0, j).Value = Sheets(i).Range("A1").Offset(FieldRow - 1, _
- Sheets(i).Range("A1:XFD1048576").Find(What:=Sheets(TargetSheetName).Range("A1").Offset(0, j).Value).Column - 1).Value
- Next j
- End If
- End With
- Next i
- On Error GoTo 0
- With Sheets(TargetSheetName).Range("A3").Offset(FieldNumber * (EndingSheet - StartingSheet + 2), 0).Resize(EndingSheet - StartingSheet + 1, MonthsBackInTime + 1)
- .NumberFormat = "#,###"
- .Borders.LineStyle = xlContinuous
- .Borders.Weight = xlThin
- .Borders.ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Interior.Color = RGB(118, 147, 60)
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement