After some trys I got this:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False 'Deactivate ScreenUpdating for better performance
Application.DisplayAlerts = False 'Deactivate DisplayAlerts to prevent the pop-up of VLOOKUP
Dim ArrMonth As Variant 'Create Array of the months, alternatives possible
ArrMonth = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
Dim i As Integer 'Counting var
Const FilePath As String = "\\shared_network\Task List\2018 Task List\02.DLP TISR\Statistics\ECM\" 'Dir to the Files; make sure the "\" is at the end
Const Table As String = "Sheet1" 'Remember: Every sheet needs the same name
On Error Resume Next 'Let's assume there are only errors that we can ignore
For i = LBound(ArrMonth) To UBound(ArrMonth) 'Circle through every single month
If Dir(FilePath & "incident_summary - " & ArrMonth(i) & ".csv") = "" Then 'If the Dir is non-existened, Dir(...) returns not null, but "", so if "" occurs, this path doesn't exist
Stop 'Stop right here if Dir non-existening
Else
Range("C14:C19").Offset(i * 6, 0).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],'" & FilePath & "[incident_summary - " & ArrMonth(i) & ".csv]" & Table & "'!R3C2:R8C3,2,FALSE),0)" 'Do what I want you to do
End If
Next i
Application.ScreenRefresh 'Refresh the Screen to update the diffrences
Application.ScreenUpdating = True 'Reactivate ScreenUpdating, bc it won't activate itself
Application.DisplayAlerts = True 'Reactivate DisplayAlerts, bc it won't reactivate itself
End Sub
After having more information this should work:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False 'Deactivate ScreenUpdating for better performance
Application.DisplayAlerts = False 'Deactivate DisplayAlerts to prevent the pop-up of VLOOKUP
Dim ArrMonth As Variant 'Create Array of the months, alternatives possible
ArrMonth = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
Dim i As Integer 'Counting var
Const FilePath As String = "\\shared_network\Task List\2018 Task List\02.DLP TISR\Statistics\ECM\" 'Dir to the Files; make sure the "\" is at the end
'Leave this one out Const Table As String = "Sheet1" 'Remember: Every sheet needs the same name
On Error Resume Next 'Let's assume there are only errors that we can ignore
For i = LBound(ArrMonth) To UBound(ArrMonth) 'Circle through every single month
If Dir(FilePath & "incident_summary - " & ArrMonth(i) & ".csv") = "" Then 'If the Dir is non-existened, Dir(...) returns not null, but "", so if "" occurs, this path doesn't exist
Stop 'Stop right here if Dir non-existening
Else
'Replace This:
'Range("C14:C19").Offset(i * 6, 0).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],'" & FilePath & "[incident_summary - " & ArrMonth(i) & ".csv]" & Table & "'!R3C2:R8C3,2,FALSE),0)" 'Do what I want you to do
'By this:
Range("C14:C19").Offset(i * 6, 0).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],'" & FilePath & "[incident_summary - " & ArrMonth(i) & ".csv]" & ArrMonth(i) & "'!R3C2:R8C3,2,FALSE),0)" 'Do what I want you to do
End If
Next i
Application.ScreenRefresh 'Refresh the Screen to update the diffrences
Application.ScreenUpdating = True 'Reactivate ScreenUpdating, bc it won't activate itself
Application.DisplayAlerts = True 'Reactivate DisplayAlerts, bc it won't reactivate itself
End Sub
ScreenUpdating = False
twice? – K.DᴀᴠɪsI
, instead of the array lookup:Format(DateSerial(1, i, 1), "MMM")
– ashleedawg