1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
Sub recup_noms_cellules_nommeesCF() 'recupere toutes les cellules nommées indiqué dans onglet CF
On Error Resume Next 'permet de continuer
Dim Dossier As Object
Dim Fichiers As Object
Dim fichier As Object
Dim Nom_Dossier As String
Dim système As Object
Dim Nom_Fichier As String
Dim wkfinal As Workbook
Set wkfinal = ThisWorkbook
If MsgBox("Etes-vous certain de vouloir ajouter des cellules nommées provenant de fichiers Comptes Financiers (CF) ?", vbYesNo, "Demande de confirmation") = vbYes Then
Nom_Dossier = SelDossier("F:\docFlo\www\")
Set système = CreateObject("Scripting.FileSystemObject")
Set Dossier = système.GetFolder(Nom_Dossier)
Set Fichiers = Dossier.Files
MsgBox ("Nombre de fiche dans le repertoire : " & NombreFichiers(Nom_Dossier))
Dim N As Name
Dim PlageNom As Range
Dim i As Byte
Dim NumLigne As Byte
For Each fichier In Fichiers
Application.ScreenUpdating = False
Set FL_Data2 = ThisWorkbook.Worksheets("DATA2")
Nom_Fichier = Nom_Dossier & "\" & fichier.Name
Workbooks.Open Filename:=Nom_Fichier
Application.DisplayAlerts = False
Application.DisplayStatusBar = False
Application.Calculation = xlManual
Application.EnableEvents = False
Application.DisplayPageBreaks = False
Dim Fichier_courant As Workbook
Dim Onglet_courrant As Worksheet
On Error Resume Next
Dim FL1 As Worksheet, NoCol As Integer
Dim NoLig As Long, Var As Variant
Set FL1 = wkfinal.Sheets("CF_Data")
NoCol = 2 'lecture de la colonne 1
For NoLig = 2 To Split(FL1.UsedRange.Address, "$")(4)
Var = FL1.Cells(NoLig, NoCol)
If Not IsEmpty(Var) Then
'If PlageNom.Value = Var Then 'And PlageNom.Value <> "" Then
k = Var
'MsgBox k
Z = Range(Var).RefersToRange.Value
'MsgBox Z
If FL_Data2.Range("Data2").Value <> "" Then
derligne = FL_Data2.Range("A65536").End(xlUp).Row + 1
Else
derligne = FL_Data2.Range("A65536").End(xlUp).Row
End If
wkfinal.Sheets("DATA2").Cells(derligne, 1).Value = fichier.Name
wkfinal.Sheets("DATA2").Cells(derligne, 2).Value = Var
wkfinal.Sheets("DATA2").Cells(derligne, 3).Value = Range(Var).Value
'******************************* complétude de la colonne 4 = N° Finess
wkfinal.Sheets("DATA2").Cells(derligne, 4).Value = Finess(fichier.Name)
'******************************* complétude de la colonne 5 = Type document
wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = Left(fichier.Name, InStr(fichier.Name, "_") - 1)
'******************************* complétude de la colonne 6 = N° Année
'MsgBox Mid(fichier.Name, 1, (WorksheetFunction.Substitute("_", fichier.Name, 6)) - 1)
wkfinal.Sheets("DATA2").Cells(derligne, 6).Value = Right(Mid(fichier.Name, 1, (Application.WorksheetFunction.Find("_", fichier.Name, 6)) - 1), 4)
'******************************* colonne 7 = Source de la cellule nommée
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "CF" Then
wkfinal.Sheets("DATA2").Cells(derligne, 7).Value = WorksheetFunction.VLookup(Var, Sheets("CF_Data").Range("B2:c200"), 2, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "EPRD" Then
wkfinal.Sheets("DATA2").Cells(derligne, 7).Value = WorksheetFunction.VLookup(Var, Sheets("EPRD_Data").Range("B2:c200"), 2, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "RIA1" Then
wkfinal.Sheets("DATA2").Cells(derligne, 7).Value = WorksheetFunction.VLookup(Var, Sheets("RIA1_Data").Range("B2:c200"), 2, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "RIA2" Then
wkfinal.Sheets("DATA2").Cells(derligne, 7).Value = WorksheetFunction.VLookup(Var, Sheets("RIA2_Data").Range("B2:c200"), 2, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "RIA3" Then
wkfinal.Sheets("DATA2").Cells(derligne, 7).Value = WorksheetFunction.VLookup(Var, Sheets("RIA1_Data").Range("B2:c200"), 2, False)
End If
'******************************* complétude de la colonne 8 = N° colonne
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "CF" Then
wkfinal.Sheets("DATA2").Cells(derligne, 8).Value = WorksheetFunction.VLookup(Var, Sheets("CF_Data").Range("B2:D200"), 3, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "EPRD" Then
wkfinal.Sheets("DATA2").Cells(derligne, 8).Value = WorksheetFunction.VLookup(Var, Sheets("EPRD_Data").Range("B2:D200"), 3, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "RIA1" Then
wkfinal.Sheets("DATA2").Cells(derligne, 8).Value = WorksheetFunction.VLookup(Var, Sheets("RIA1_Data").Range("B2:D200"), 3, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "RIA2" Then
wkfinal.Sheets("DATA2").Cells(derligne, 8).Value = WorksheetFunction.VLookup(Var, Sheets("RIA2_Data").Range("B2:D200"), 3, False)
End If
If wkfinal.Sheets("DATA2").Cells(derligne, 5).Value = "RIA3" Then
wkfinal.Sheets("DATA2").Cells(derligne, 8).Value = WorksheetFunction.VLookup(Var, Sheets("RIA3_Data").Range("B2:D200"), 3, False)
End If
End If
Next
ActiveWorkbook.Close
Set FL1 = Nothing
Next 'fichier
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.DisplayPageBreaks = True
End If
End Sub |
Partager