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
| Sub test()
Dim wk1 As Workbook, wk2 As Workbook, baseSh, sht
Dim nb As Integer, i As Integer, y As Integer, col As Integer, nba As Integer
Dim add1 As String, t As String, nn As String, verif As String
Dim n As Long
Set wk1 = ThisWorkbook
Set wk2 = Workbooks("Le Panel 2017 par région_fichiers_régionaux.xlsm")
baseSh = Array("persp cad X taille", "persp sal X taille", "perps cad X grd secteur", "persp sal X grd secteur", "persp cad X dpt", "perps sal X dpt")
For Each sht In Worksheets
verif = sht.Name
If sht.Name <> "feuil1" Then
ligne1 = Application.Match("Par taille d'établissement", Sheets(sht.Name).Range("A:A"), 0) + 1
ligne2 = Application.Match("Par département", Sheets(sht.Name).Range("A:A"), 0) - 3
ligne3 = Application.Match("Par grands secteurs", Sheets(sht.Name).Range("A:A"), 0) + 1
plg1 = Range(Cells(ligne1, 1), Cells(ligne2, 1)).Address
nb = Application.CountA(Sheets(sht.Name).Range(plg1))
nn = """" & sht.Name & """"
col = 2
For i = 0 To 1
add1 = "'[" & wk2.Name & "]" & baseSh(i) & "'!"
t = "MATCH(" & nn & "," & CStr(add1) & "$A:$A,0)"
n = Evaluate(t)
For y = 0 To nb - 1
Sheets(sht.Name).Cells(ligne1 + y, col).Value = wk2.Sheets(baseSh(i)).Cells(y + n, 3).Value
Sheets(sht.Name).Cells(ligne1 + y, col + 1).Value = wk2.Sheets(baseSh(i)).Cells(y + n, 4).Value
Next y
col = 6
Next i
col = 2
For i = 2 To 3
add1 = "'[" & wk2.Name & "]" & baseSh(i) & "'!"
t = "MATCH(" & nn & "," & CStr(add1) & "$A:$A,0)"
n = Evaluate(t)
For y = 0 To 3
Sheets(sht.Name).Cells(ligne3 + y, col).Value = wk2.Sheets(baseSh(i)).Cells(y + n, 3).Value
Sheets(sht.Name).Cells(ligne3 + y, col + 1).Value = wk2.Sheets(baseSh(i)).Cells(y + n, 4).Value
Next y
col = 6
Next i
plg2 = Range(Cells(ligne2, 1), Cells(ligne2, 1)).Address
nba = Application.CountA(Sheets(sht.Name).Range(plg2))
nn = """" & sht.Name & """"
col = 2
For i = 4 To 5
add1 = "'[" & wk2.Name & "]" & baseSh(i) & "'!"
t = "MATCH(" & nn & "," & CStr(add1) & "$A:$A,0)"
n = Evaluate(t)
For y = 0 To nba - 1
Sheets(sht.Name).Cells(ligne2 + y, col).Value = wk2.Sheets(baseSh(i)).Cells(y + n, 3).Value
Sheets(sht.Name).Cells(ligne2 + y, col + 1).Value = wk2.Sheets(baseSh(i)).Cells(y + n, 4).Value
Next y
col = 6
Next i
End If
Next
End Sub |
Partager