Option Explicit
Public i, j, k, l, m As Integer, row, lastRow, lastRowPastDue, lastRowPaidOff, lastRowToCxl, lastRowToTxf, matchFoundIndex As Long
Public wb, wb2, wbsource, wbdest As Workbook
Public ws, wssource, wsdest As Worksheet
Public strDate As String
Public CurrentDate, PriorDate As Date
Public MonthNameSel, YearSel As String
Public EOMday As String
Public SeqNum, PriorSeqNum As String
Public MonthNm, PriorMoNm As String
Public MonthNum, PriorMoNo As String
Public PriorMoYear As String
Public strSearch1, strSearch2 As String
Public Pool, PoolName, PoolNo, PoolNo2, PoolNo3 As String
Public r, rCell, SelectCell, Rng1, Rng2, TimeRng, SourceRng As Range
Public filterCriteria, arr As Variant
Dim answer, note, myString, ary As String
'set folder path file string naming conventions
Public Function strPath() As String
strPath = "\\usnvfsa0\accounting$\Office Records\Accounting - NEW\"
End Function
Public Function folderPath() As String
folderPath = SeqNum & " " & YearSel & " Business Records\Servicer Related Documents - FIN 220\WAAM Reporting\"
End Function
Public Function PriorFolderPath() As String
PriorFolderPath = PriorSeqNum & " " & PriorMoYear & " Business Records\Servicer Related Documents - FIN 220\WAAM Reporting\"
End Function
Public Function PriorFolderPath2() As String
PriorFolderPath2 = PriorSeqNum & " " & PriorMoYear & " Business Records\Servicer Related Documents - FIN 220\WAAM Reporting\"
End Function
Public Function FolderPath2() As String
FolderPath2 = PriorSeqNum & " " & PriorMoYear & " Business Records\Servicer Related Documents - FIN 220\WAAM Reporting\"
End Function
Public Function FolderMo() As String
FolderMo = MonthNum & " " & MonthNameSel & "\"
End Function
Public Function PriorFolderMo() As String
PriorFolderMo = PriorMoNo & " " & PriorMoNm & "\"
End Function
Public Function FolderMo2() As String
FolderMo2 = MonthNum & " " & MonthNameSel
End Function
Public Function QueryFolder() As String
QueryFolder = "HyperionQueries"
End Function
Public Function ServicerName() As String
ServicerName = YearSel & "_" & MonthNum & "_" & Pool & " Servicer Report"
End Function
Public Function PriorServicerName() As String
PriorServicerName = PriorMoYear & "_" & PriorMoNo & "_" & Pool & " Servicer Report"
End Function
Public Function SRInputName() As String
SRInputName = YearSel & "_" & MonthNum & "_WAAM SRInput"
End Function
Public Function PriorSRInputName() As String
PriorSRInputName = PriorMoYear & "_" & PriorMoNo & "_WAAM SRInput"
End Function
''''''''''''HERE"S THE CODE Prior to the below section of code, user forms collect values for month, year, and pool number which are used in the naming conventions.
SRInputFilter()
Set wbdest = Workbooks.Open(strPath & folderPath & FolderMo & ServicerName & ".xlsx", WriteResPassword:="XXXX", UpdateLinks:=0) 'open report (destination)
Set wsdest = wbdest.Sheets("Manual Transfers")
With wsdest 'capture any "processing error" when From pool(column E) & To pool (column F) codes are identical & highlight row yellow
lastRow = wsdest.Range("C1000").End(xlUp).row
For i = 3 To lastRow
'=====>>>>NONE OF THE FOLLOWING RUNS FROM THE EXCEL MACRO, BUT IT DOES WHEN RUNNING OUT OF VISUAL BASIC EDITOR
If Range("E" & i) = Range("F" & i) Then 'if from pool code in column E = to pool code in column F
Range("G" & i).Copy 'copy value from balance (column G) to column H (for reference note - data not used)
Range("H" & i).PasteSpecial xlPasteValues
Range("G" & i).Interior.Color = vbYellow 'highlight column G's cell in yellow
Range("G" & i).ClearContents 'clear column G's cell value
End If
Next i
End With
'move past due & paid off activities to lower tab areas
If PoolNo = "6" Then
'With wsdest
lastRow = wsdest.Range("C1000").End(xlUp).row
j = 1039 'to reference for beginning paid off 11-6 section data row1
k = 1026 'to reference for beginning past due 11-6 section data row1
m = 1016 'to reference for beginning transfers from 6-11 section row1
l = 1001 'to reference for beginning to be cxld 5-6 section data row1
For i = 3 To lastRow 'data begins on row 3
If Cells(i, 5) = "11" And Cells(i, 7) <> "" Then 'if from pool (column E) = 11 and balance (column G) is not empty
If Cells(i, 7) >= "0" Then 'if balance >= 0 need to move to Past Dues section
k = k + 1
Range("A" & i & ":G" & i).Copy 'move row values to past at bottom & clear top area row values
Range("A" & k & ":G" & k).PasteSpecial xlPasteValues
Range("A" & i & ":G" & i).ClearContents
End If
If Cells(i, 7) < "0" Then 'if balance <0 need to move to Paid Offs section
j = j + 1
Range("A" & i & ":G" & i).Copy 'move row values to past at bottom & clear top area row values
Range("A" & j & ":G" & j).PasteSpecial xlPasteValues
Range("A" & i & ":G" & i).ClearContents
End If
If Cells(i, 5) = "5" Then 'if balance from pool (column E) = 5, move to below (to be cancelled) section
l = l + 1
Range("A" & i & ":G" & i).Copy
Range("A" & l & ":G" & l).PasteSpecial xlPasteValues
Range("A" & i & ":G" & i).ClearContents
End If
End If
Next i
'hide empty rows in past due & paid off sections
lastRowToCxl = wsdest.Range("G1012").End(xlUp).row
lastRowToCxl = lastRowToCxl + 1
wsdest.Rows(lastRowToCxl & ":1011").EntireRow.Hidden = True
lastRowToTxf = wsdest.Range("G1025").End(xlUp).row
lastRowToTxf = lastRowToTxf + 1
wsdest.Rows(lastRowToTxf & ":1024").EntireRow.Hidden = True
lastRowPastDue = wsdest.Range("G1038").End(xlUp).row
lastRowPastDue = lastRowPastDue + 1
wsdest.Rows(lastRowPastDue & ":1037").EntireRow.Hidden = True
lastRowPaidOff = wsdest.Range("G1051").End(xlUp).row
lastRowPaidOff = lastRowPaidOff + 1
wsdest.Rows(lastRowPaidOff & ":1050").EntireRow.Hidden = True
'End With
End If
If PoolNo = "5" Then
'hide empty rows in past due & paid off sections
lastRowToTxf = wsdest.Range("G1010").End(xlUp).row
lastRowToTxf = lastRowToCxl + 1
wsdest.Rows(lastRowToTxf & ":1009").EntireRow.Hidden = True
End If
Set wbsource = Workbooks.Open(strPath & folderPath & FolderMo & SRInputName & ".xlsx", UpdateLinks:=0) 'open SRInput (source)
Set wssource = wbsource.Sheets("Funding")
'stamp destination sheet with time & doc source
Set TimeRng = wsdest.Range("C1")
Set SourceRng = wsdest.Range("E1")
SourceRng.Value = strPath & folderPath & FolderMo & SRInputName & ".xlsx" '
TimeRng.Value = Format(Now(), "mm/dd/yy hh:mm")
'copy Removals - Paid off
Set wssource = wbsource.Sheets("Removals")
Set wsdest = wbdest.Sheets("Xfr To (Auto)-Paid Off")
With wssource
'.AutoFilterMode = False
.UsedRange.AutoFilter
.Range("C:C").AutoFilter Field:=3, Criteria1:="*" & PoolNo & "*" 'filter for pool code either from or to in column C
.Range("I:I").AutoFilter Field:=9, Criteria1:="CONTRACT PAID OFF" 'Filter Contract Paid Off only
.Range("A1:O99").Copy
End With
With wbdest.Sheets("Xfr To (Auto)-Paid Off").Range("A2")
.PasteSpecial (xlPasteValues), Operation:=xlNone, skipblanks:=False, Transpose:=False 'copy source to destination
Application.CutCopyMode = False
End With
'clear if any ASO duplicate processing entries
lastRow = wsdest.Range("A99").End(xlUp).row
row = 3
With wsdest
lastRow = lastRow + 1
wsdest.Rows(lastRow & ":98").EntireRow.Hidden = True 'hide section's empty data rows
'stamp destination sheet with time & doc source
Set TimeRng = wsdest.Range("C1")
Set SourceRng = wsdest.Range("E1")
SourceRng.Value = strPath & folderPath & FolderMo & SRInputName & ".xlsx"
TimeRng.Value = Format(Now(), "mm/dd/yy hh:mm")
End With
'copy Transfers - Aged
Set wsdest = wbdest.Sheets("Xfr To (Auto)-Aged")
Set wssource = wbsource.Sheets("Removals")
With wssource
.AutoFilterMode = False
.UsedRange.AutoFilter
.Range("C:C").AutoFilter Field:=3, Criteria1:="*" & PoolNo & "*" 'filter for pool code either from or to in column C"
.Range("I:I").AutoFilter Field:=9, Criteria1:="<>CONTRACT PAID OFF" 'filter all excluding Paid Off
.Range("A1:O99").Copy
End With
With wbdest.Sheets("Xfr To (Auto)-Aged").Range("A2")
.PasteSpecial (xlPasteValues), Operation:=xlNone, skipblanks:=False, Transpose:=False 'copy source to destination
Application.CutCopyMode = False
End With
'clear if any ASO duplicate processing entries
lastRow = wsdest.Range("A99").End(xlUp).row
row = 3
With wsdest
lastRow = lastRow + 1
wsdest.Rows(lastRow & ":98").EntireRow.Hidden = True 'hide section's empty data rows
'stamp destination sheet with time & doc source
Set TimeRng = wsdest.Range("C1")
Set SourceRng = wsdest.Range("E1")
SourceRng.Value = strPath & folderPath & FolderMo & SRInputName & ".xlsx" 'stamp for time & doc source
TimeRng.Value = Format(Now(), "mm/dd/yy hh:mm")
End With
'End If
wbsource.Close savechanges:=False
wbdest.Close savechanges:=True
ThisWorkbook.Worksheets("Macros").Select
MsgBox "Done!"
End Sub
Bookmarks