Option Explicit
Dim LR As Long
Dim lClientID As Long
Dim lLoanNumber As Long
Dim lFHLMC As Long
Dim lInvestor As Long
Dim lSupervisor As Long
Dim lRM As Long
Dim lStatus As Long
Dim rngData As Range
Dim lTemplateCreation As Long
Dim lTemplateAge As Long
Dim lWorkbasket As Long
Dim lSubstatus As Long
'Call variables
Dim lLMIBB As Long
Dim lLMIBO As Long
Dim lWSPOK As Long
Dim lIUPAC As Long
Dim lIUPDC As Long
Dim l1SPOK As Long
Dim l1NOCN As Long
Dim lWNOCN As Long
'Helper Columns
Dim cLastCall As Long
Dim cLastCallDays As Long
Dim cAfterTemplate As Long
Sub Last_Call_Pre()
'Assigning Variables
With Worksheets("REPORT").Activate
lClientID = Application.WorksheetFunction.Match("PARTITIONCD", Range("1:1"), 0)
lLoanNumber = Application.WorksheetFunction.Match("LOAN_NUMBER", Range("1:1"), 0)
lFHLMC = Application.WorksheetFunction.Match("FHLMC_T", Range("1:1"), 0)
lInvestor = Application.WorksheetFunction.Match("INVESTOR_TYPE", Range("1:1"), 0)
lSupervisor = Application.WorksheetFunction.Match("DW_ASSIGNEDRM_EMP_MGR", Range("1:1"), 0)
lRM = Application.WorksheetFunction.Match("DW_ASSIGNEDRM_EMP_NAME", Range("1:1"), 0)
lStatus = Application.WorksheetFunction.Match("LOSS_MIT_STATUS_CODE", Range("1:1"), 0)
lTemplateCreation = Application.WorksheetFunction.Match("LOSS_MIT_SET_UP_DATE", Range("1:1"), 0)
lTemplateAge = Application.WorksheetFunction.Match("TEMPLATE_AGE", Range("1:1"), 0)
lWorkbasket = Application.WorksheetFunction.Match("WORKBASKET", Range("1:1"), 0)
lSubstatus = Application.WorksheetFunction.Match("SUBSTATUS", Range("1:1"), 0)
'Call Variables
lLMIBB = Application.WorksheetFunction.Match("LMIBB", Range("1:1"), 0)
lLMIBO = Application.WorksheetFunction.Match("LMIBO", Range("1:1"), 0)
lWSPOK = Application.WorksheetFunction.Match("WSPOK", Range("1:1"), 0)
lIUPAC = Application.WorksheetFunction.Match("IUPAC", Range("1:1"), 0)
lIUPDC = Application.WorksheetFunction.Match("IUPDC", Range("1:1"), 0)
l1SPOK = Application.WorksheetFunction.Match("1SPOK", Range("1:1"), 0)
l1NOCN = Application.WorksheetFunction.Match("1NOCN", Range("1:1"), 0)
lWNOCN = Application.WorksheetFunction.Match("WNOCN", Range("1:1"), 0)
'Helper Column Variables
cLastCall = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
cLastCallDays = Cells(1, cLastCall).Offset(, 1).Column
cAfterTemplate = Cells(1, cLastCallDays).Offset(, 1).Column
LR = Range("A" & Rows.Count).End(xlUp).Row
Set rngData = Range("A1").CurrentRegion
'FUNCTIONS
'Max Last Call
With Range(Cells(2, cLastCall), Cells(LR, cLastCall))
.FormulaR1C1 = "=MAX(RC" & lLMIBB & ", RC" & lLMIBO & ", RC" & lWSPOK & ", RC" & lIUPAC & _
", RC" & lIUPDC & ", RC" & l1SPOK & ", RC" & l1NOCN & ", RC" & lWNOCN & ")"
End With
'Aging Since Last Call
With Range(Cells(2, cLastCallDays), Cells(LR, cLastCallDays))
.FormulaR1C1 = "=IF(RC" & cLastCall & " ="""", """", Today()- RC" & cLastCall & ")"
.NumberFormat = "0"
.Value = .Value
End With
'Equation that MAX call > template creation
With Range(Cells(2, cAfterTemplate), Cells(LR, cAfterTemplate))
.FormulaR1C1 = "=AND(RC" & cLastCall & " < RC" & lTemplateCreation & ")"
End With
End With
'Filters
With Worksheets("REPORT")
rngData.AutoFilter Field:=lStatus, Criteria1:="A"
rngData.AutoFilter Field:=cAfterTemplate, Criteria1:="FALSE"
rngData.AutoFilter Field:=lWorkbasket, Criteria1:=Array("CustomerContact", "DocChasing", "QA", "PlanBreak"), Operator:=xlFilterValues
rngData.AutoFilter Field:=lSubstatus, Criteria1:="<>" & "Confirmation of Denial"
rngData.AutoFilter Field:=cLastCall, Criteria1:="<" & Date - 2
'Client ID
LR = .Cells(.Rows.Count, lClientID).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lClientID), .Cells(LR, lClientID)).Copy _
Sheets("Last Call (Pre Dec)").Range("A3")
End If
'Loan Number
LR = .Cells(.Rows.Count, lLoanNumber).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lLoanNumber), .Cells(LR, lLoanNumber)).Copy _
Sheets("Last Call (Pre Dec)").Range("B3")
End If
'Freddie
LR = .Cells(.Rows.Count, lFHLMC).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lFHLMC), .Cells(LR, lFHLMC)).Copy _
Sheets("Last Call (Pre Dec)").Range("C3")
End If
'Investor
LR = .Cells(.Rows.Count, lInvestor).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lInvestor), .Cells(LR, lInvestor)).Copy _
Sheets("Last Call (Pre Dec)").Range("D3")
End If
'Supervisor
LR = .Cells(.Rows.Count, lSupervisor).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lSupervisor), .Cells(LR, lSupervisor)).Copy _
Sheets("Last Call (Pre Dec)").Range("E3")
End If
'RM
LR = .Cells(.Rows.Count, lRM).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lRM), .Cells(LR, lRM)).Copy _
Sheets("Last Call (Pre Dec)").Range("F3")
End If
'Workbasket
LR = .Cells(.Rows.Count, lWorkbasket).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lWorkbasket), .Cells(LR, lWorkbasket)).Copy _
Sheets("Last Call (Pre Dec)").Range("G3")
End If
'Substatus
LR = .Cells(.Rows.Count, lSubstatus).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, lSubstatus), .Cells(LR, lSubstatus)).Copy _
Sheets("Last Call (Pre Dec)").Range("H3")
End If
'Days Since Last Call
LR = .Cells(.Rows.Count, cLastCallDays).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, cLastCallDays), .Cells(LR, cLastCallDays)).Copy _
Sheets("Last Call (Pre Dec)").Range("I3")
End If
End With
'Delete extra column and Clears filter on REPORT
With Worksheets("REPORT")
ActiveSheet.ShowAllData
Columns(cAfterTemplate).Select
Selection.Delete
Columns(cLastCallDays).Select
Selection.Delete
Columns(cLastCall).Select
Selection.Delete
.Range("A1").Select
End With
Sheets("Last Call (Pre Dec)").Select
'Range Filldowns
With Worksheets("Last Call (Pre Dec)")
'Last Call Aging Range
With .Range("J3", Range("I" & Rows.Count).End(xlUp).Offset(, 1))
.FormulaR1C1 = "=IF(RC[-1] < 6, ""1-5 Days"", If(AND(RC[-1] >=6, RC[-1] <=10), ""6-10 Days"", ""> 10 Days""))"
.Value = .Value
End With
End With
Call Last_Call_Post
End Sub
Bookmarks