I'm trying to import data from multiple workbooks (excel files selected by File Picker dialog box ) into one single workbook. Each workbook contains 3 sheets, both workbook and sheets source and workbooks and sheets destination have the same structure. The code is already working if I select one file, but does not copy results in destination sheet if I select 2 or more files. I tried different solutions but the vba code is new for me and I cannot figure out what's wrong. Could someone tell what's wrong with the code please?
Const premiere_ligne_J = 6
Sub import_donnees_J(chemin_tem)
Application.Calculation = xlCalculationManual
Dim dataJ As Worksheet
Set dataJ = ThisWorkbook.Worksheets("Import data Sheet 1")
Dim Ctr
Application.DisplayAlerts = False
For Ctr = 1 To Application.FileDialog(msoFileDialogFilePicker).SelectedItems.Count
Workbooks.Open (chemin_tem)
tem = ActiveWorkbook.Name
Workbooks(tem).Activate
Application.DisplayAlerts = True
Set templateJ = Workbooks(tem).Sheets("Import data Sheet 1")
dernier_client = templateJ.Range("A" & Rows.Count).End(xlUp).Row
ligne = premiere_ligne_J
For client = premiere_ligne_J To dernier_client
'Copying data
For col = colJ_pdl_data To colJ_rapport_precision_data
dataJ.Cells(ligne, col) = templateJ.Cells(client, col)
Next col
ligne = ligne + 1
suite::
Next client
Workbooks(tem).Close SaveChanges:=False
Next Ctr
Application.Calculation = xlCalculationAutomatic
End Sub`
This fuction is almost the same for the 3 sheets to import.
The main program calls these functions
Call Import1.import_donnees_J(chemin_tem)
Call Import2.import_donnees_V(chemin_tem)
Call Import3.import_donnees_B(chemin_tem)
Chemin_tem is defined as below :
chemin_tem = CStr(Application.FileDialog(msoFileDialogFilePicker).SelectedItems(1))