Ideally, if s or sD aren't found, I'd like to update the last cell in a range. I haven't been able to get that cell to update if s is missing. Thoughts?
VBA Code:
Option Explicit
Sub ImportT()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim m As Workbook, s As Workbook
Dim mO As Worksheet, sD As Worksheet, mV As Worksheet
Dim fP As String, fN As String, fE As String
Dim mOLR As Long, sDLR As Long, mVLR As Long
Dim uDP As String
Set m = ThisWorkbook
Set mO = m.Sheets("Org Info")
Set mV = m.Sheets("Variables")
uDP = CreateObject("WScript.Shell").SpecialFolders("Desktop")
mVLR = mV.Range("L" & Rows.Count).End(xlUp).Row
fP = uDP & "\Import Files\"
fN = "Org T"
fN = Dir(fP & fN & "*.xlsx")
On Error GoTo MissingFile
If Len(Dir(fP & fN, vbDirectory)) > 0 Then
Set s = Workbooks.Open(fP & fN)
Set sD = s.Sheets("Data")
'Removes filters from the working data if any exist.
If mO.AutoFilterMode Then mO.AutoFilterMode = False
'Unhides any columns and rows that may be hidden on the working data.
With mO.UsedRange
.Columns.EntireColumn.Hidden = False
.Rows.EntireRow.Hidden = False
End With
mOLR = mO.Range("A" & Rows.Count).End(xlUp).Row
sDLR = sD.Range("A" & Rows.Count).End(xlUp).Row
With sD.Range("H2:H" & sDLR).Copy
mO.Range("A" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("A2:G" & sDLR).Copy
mO.Range("B" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("I2:M" & sDLR).Copy
mO.Range("I" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("X2:X" & sDLR).Copy
mO.Range("N" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("BI2:BI" & sDLR).Copy
mO.Range("O" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("CK2:CK" & sDLR).Copy
mO.Range("T" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("CL2:CL" & sDLR).Copy
mO.Range("S" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("CM2:CM" & sDLR).Copy
mO.Range("R" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("CN2:CN" & sDLR).Copy
mO.Range("Q" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("CO2:CO" & sDLR).Copy
mO.Range("P" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("H2:H" & sDLR).Copy
mO.Range("U" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("Y2:Y" & sDLR).Copy
mO.Range("V" & mOLR + 1).PasteSpecial xlPasteValues
End With
With sD.Range("AA2:AA" & sDLR).Copy
mO.Range("W" & mOLR + 1).PasteSpecial xlPasteValues
End With
s.Close SaveChanges:=False
Else
Err.Raise 53
mV.Range("L" & mVLR + 1).Value = "Org-T"
End If
MissingFile:
'mV.Range("L" & mVLR + 1).Value = "Org-T" --- Is updating every import file.
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub