Optimisation : comme une rechercheV
Bonjour, cela fait un certain temps que je programme en VBA mais je reste sur une question que je me pose fréquemment.
En effet, je reprogramme régulièrement en vba le code qui permet de faire comme une rechercheV.
Comment puis je l'optimiser? Y a t il une fonction déjà faites? Je fais appelle à vos connaissances.
Je vous mets mon codes :
Code:
1 2 3 4 5
| Sub part_descr()
remplissage "Enveloppe_NPT", 4, "NPT_Analyse", 3
End Sub |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Sub remplissage(nom_feuille_origine, num_colonne_origine, nom_feuille_destination, num_colonne_destination)
Dim compteur1, compteur2, max1, max2 As Integer
Dim ref1, ref2 As String
max1 = max_ligne(nom_feuille_origine, 1)
max2 = max_ligne(nom_feuille_destination, 1)
For compteur2 = 2 To max2
ref2 = Sheets(nom_feuille_destination).Cells(compteur2, 1).Value
For compteur1 = 2 To max1
ref1 = Sheets(nom_feuille_origine).Cells(compteur1, 1).Value
If ref1 = ref2 Then
Sheets(nom_feuille_destination).Cells(compteur1, num_colonne_destination).Value = Sheets(nom_feuille_origine).Cells(compteur1, num_colonne_origine).Value
Exit For
End If
Next
Next
End Sub |
Code:
1 2 3 4 5
| Function max_ligne(nom_feuille, num_colonne)
max_ligne = Sheets(nom_feuille).Cells(Rows.Count, num_colonne).End(xlUp).Row
End Function |
Merci d'avance pour vos réponses.
Vincent