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
| Sub recup()
Dim tb, tb2, tb3, tb4, x As Long, y As Long, Mess As String, Ch As Long
Dim WS As Worksheet, a As Long, z As Long
Ch = 0: a = 1
Mess = InputBox("valeur à récupérer")
tb2 = Sheets("Feuil2").UsedRange
tb3 = Sheets("Feuil3").UsedRange
tb4 = Sheets("Feuil4").UsedRange
For Each WS In Worksheets
For x = 1 To WS.UsedRange.Rows.Count
For y = 1 To WS.UsedRange.Columns.Count
If WS.Cells(x, y) = Mess Then Ch = Ch + 1 'pour la 1ère dimension du tableau "tb"
Next y
Next x
Next WS
ReDim tb(1 To Ch, 1 To 25) 'derniere colonne "Y"
For x = 1 To UBound(tb2, 1)
For y = 1 To UBound(tb2, 2)
If tb2(x, y) = Mess Then
tb(a, 2) = tb2(x, 2) 'prend la donnée de B10
tb(a, 4) = tb2(x, 4) 'prend la donnée de D10
tb(a, 7) = tb2(x, 7) 'prend la donnée de G10
a = a + 1
End If
Next y
Next x
For x = 1 To UBound(tb3, 1)
For y = 1 To UBound(tb3, 2)
If tb3(x, y) = Mess Then
tb(a, 2) = tb2(x, 2) 'prend la donnée de B4
tb(a, 3) = tb2(x, 3) 'prend la donnée de C4
tb(a, 6) = tb2(x, 6) 'prend la donnée de F4
tb(a, 7) = tb2(x, 7) 'prend la donnée de G4
a = a + 1
End If
Next y
Next x
For x = 1 To UBound(tb4, 1)
For y = 1 To UBound(tb4, 2)
If tb4(x, y) = Mess Then
tb(a, 3) = tb2(x, 3) 'prend la donnée de C3
tb(a, 4) = tb2(x, 4) 'prend la donnée de D3
tb(a, 11) = tb2(x, 11) 'prend la donnée de K3
tb(a, 22) = tb2(x, 22) 'prend la donnée de V3
tb(a, 25) = tb2(x, 25) 'prend la donnée de Y3
a = a + 1
End If
Next y
Next x
Sheets("Feuil1").Range("A2").Resize(UBound(tb, 1), UBound(tb, 2)) = tb 'à partir de A2, on intègre le résultat
End Sub |
Partager