Option Explicit: Option Compare Text
'plusieurs subs de rechercheV (= VLookup en VBA)
Sub Numérique() 'pour les désignations numériques
Dim resultats(1 To 1000, 1 To 3), dlA&, dlM&, j&
With Sheets("Eléments - MTO")
dlA = .Cells(.Rows.Count, 1).End(xlUp).Row: dlM = .Cells(.Rows.Count, 13).End(xlUp).Row
For j = 5 To dlM
resultats(j - 4, 1) = Application.VLookup(Range("M" & j), Sheets("Base de données").Range("A5:C" & dlA), 2, 0)
Next j
.Range("O5").Resize(UBound(resultats)) = WorksheetFunction.IfError(resultats, "")
End With
End Sub
Sub Groupe() 'pour les groupes de matériaux
Dim resultats(1 To 1000, 1 To 3), dlA&, dlM&, j&
With Sheets("Eléments - MTO")
dlA = .Cells(.Rows.Count, 1).End(xlUp).Row: dlM = .Cells(.Rows.Count, 13).End(xlUp).Row
For j = 5 To dlM
resultats(j - 4, 1) = Application.VLookup(Range("M" & j), Sheets("Base de données").Range("A5:C" & dlA), 3, 0)
Next j
.Range("Q5").Resize(UBound(resultats)) = WorksheetFunction.IfError(resultats, "")
End With
End Sub
Sub DN_1() 'pour les DN (1)
Dim resultats(1 To 1000, 1 To 3), dlA&, dlM&, j&
With Sheets("Eléments - MTO")
dlA = .Cells(.Rows.Count, 1).End(xlUp).Row: dlM = .Cells(.Rows.Count, 13).End(xlUp).Row
For j = 5 To dlM
resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:X" & dlA), 5, 0)
Next j
.Range("X5").Resize(UBound(resultats)) = WorksheetFunction.IfError(resultats, "")
End With
End Sub
Sub DN_2() 'pour les DN (2)
Dim resultats(1 To 1000, 1 To 3), dlA&, dlM&, j&
With Sheets("Eléments - MTO")
dlA = .Cells(.Rows.Count, 1).End(xlUp).Row: dlM = .Cells(.Rows.Count, 13).End(xlUp).Row
For j = 5 To dlM
resultats(j - 4, 1) = Application.VLookup(Range("CB" & j), Sheets("Base de données").Range("T5:X" & dlA), 5, 0)
Next j
.Range("Y5").Resize(UBound(resultats)) = WorksheetFunction.IfError(resultats, "")
End With
End Sub
Sub Masses() 'pour les masses
Dim resultats(1 To 1000, 1 To 3), dlA&, dlM&, j&
With Sheets("Eléments - MTO")
dlA = .Cells(.Rows.Count, 1).End(xlUp).Row
dlM = .Cells(.Rows.Count, 13).End(xlUp).Row
For j = 5 To dlM
' Tube
If (Range("R" & j) = "Tube") Then resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:AD" & dlA), 11, 0)
' Coude
If (Range("S" & j) = "2D/SR 45°") Then resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:AP" & dlA), 23, 0)
If (Range("S" & j) = "2D/SR 90°") Then resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:AS" & dlA), 26, 0)
If (Range("S" & j) = "3D/LR 45°") Then resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:AV" & dlA), 29, 0)
If (Range("S" & j) = "3D/LR 90°") Then resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:AY" & dlA), 32, 0)
' Té égal
If (Range("S" & j) = "Egal") Then resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:BB" & dlA), 35, 0)
' Caps
If (Range("R" & j) = "Caps") Then resultats(j - 4, 1) = Application.VLookup(Range("CA" & j), Sheets("Base de données").Range("T5:BE" & dlA), 38, 0)
' Bride
If (Range("R" & j) = "Bride") Then resultats(j - 4, 1) = Application.VLookup(Range("CC" & j), Sheets("Base de données").Range("BJ5:BN" & dlA), 5, 0)
Next j
.Range("AF5").Resize(UBound(resultats)) = WorksheetFunction.IfError(resultats, "")
End With
End Sub