Option Explicit
Sub ImportSubData()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim m As Workbook, s As Workbook
Dim mD As Worksheet, sD As Worksheet
Dim MaxDt As Date
Dim fP As String, fN As String, fE As String
Dim mDLR As Long, mNLR As Long, sDLR As Long
Set m = ThisWorkbook
Set mD = m.Sheets("Data")
mDLR = mD.Range("A" & Rows.Count).End(xlUp).Row
'Opens and sets the source file.
fP = "C:\Users\K085613\Desktop\Import Files\"
fN = "Sub"
fN = Dir(fP & fN & "*.xlsx")
Set s = Workbooks.Open(fP & fN)
Set sD = s.Sheets("Sheet 1")
sDLR = sD.Range("A" & Rows.Count).End(xlUp).Row
sD.Activate
'Removes filters from the working data if any exist.
If sD.AutoFilterMode Then sD.AutoFilterMode = False
'Unhides any columns and rows that may be hidden on the working data.
With sD.UsedRange
.Columns.EntireColumn.Hidden = False
.Rows.EntireRow.Hidden = False
End With
'Populates the Loan Number column.
With sD.Range("C2:C" & sDLR).Copy
mD.Range("F" & mDLR + 1).PasteSpecial xlPasteValues
End With
'Populates the Decision Date column.
With sD.Range("B2:B" & sDLR).Copy
mD.Range("G" & mDLR + 1).PasteSpecial xlPasteValues
End With
'Populates the Decision column.
'Not applicable for this data source.
With sD.Range("B2:B" & sDLR).Copy
mD.Range("I" & mDLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("F2:F" & sDLR).Copy
mD.Range("L" & mDLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("H2:H" & sDLR).Copy
mD.Range("M" & mDLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("I2:I" & sDLR).Copy
mD.Range("P" & mDLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("G2:G" & sDLR).Copy
mD.Range("Q" & mDLR + 1).PasteSpecial xlPasteValues
End With
mNLR = mD.Range("F" & Rows.Count).End(xlUp).Row
'Populates the LOB column.
mD.Range("A" & mDLR + 1 & ":A" & mNLR).Value = "Sub"
'Populates the Data Source column.
mD.Range("B" & mDLR + 1 & ":B" & mNLR).Value = "Sub-Data"
'Populates the Review Type column.
mD.Range("C" & mDLR + 1 & ":C" & mNLR).Value = "LOB"
'sDLR = sD.Range("A" & Rows.Count).End(xlUp).Row
'Populates the Source Publicated/Last Updated column.
With mD.Range("D" & mDLR + 1 & ":D" & mNLR)
'.Value = "=MAX('[Sub-HEPMO.xlsx]Sheet 1'!C[-2]:C[-2])"
'.Value = Application.WorksheetFunction.Max(sD.Columns("B"))
'.Value = Application.WorksheetFunction.Max(sD.Range("B2:B" & sDLR))
MaxDt = Application.WorksheetFunction.Max(sD.Range("B2:B" & sDLR))
'MaxDt = Application.WorksheetFunction.Max(s.Sheets("Sheet 1").Range("B2:B" & Rows.Count).End(xlUp).Row)
.Value = CDate(MaxDt)
'.Value = .Value
'.FormulaR1C1 = "=MAX(" & "'[" & s.Name & "]Sheet 1'!C[-2]:C[-2])"
'.Value = Replace(Left(Right(s.Name, 13), 8), ".", "/")
'.Value = .Value
End With
'Populates the Source Ingested column.
With mD.Range("E" & mDLR + 1 & ":E" & mNLR)
.Value = "=TODAY()"
.Value = .Value
End With
With mD.Range("J" & mDLR + 1 & ":J" & mNLR)
.Value = "=IF(RC[-1]="""","""",RC[-1])"
.NumberFormat = "MMM-YY"
.Value = .Value
End With
With sD.Range("D2:D" & sDLR).Copy
mD.Range("K" & mDLR + 1).PasteSpecial xlPasteValues
End With
s.Close SaveChanges:=False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub