bonjour,
C'est mon premier post sur ce forum.
J'ai besoin de votre aide car j'ai suis bloqué avec le find.
Je souhaiterai améliorer la rapidité d’exécution de ma macro. La structure de mon code ressemblait globalement à ça :
cette structure de double boucle for imbriquées fonctionnait mais était très lente la macro 30 sec env pour s’exécuter.Code:
1
2
3
4
5
6
7
8
9 for i = 0 to maxLigneCol1whs1 "parcours toute la colonne des noms dans worksheet1" for y = 0 to maxLigneCol1wsh2 "parcours toute la colonne des noms dans worksheet2" if wsh1.Range("A" & i).value = wsh2.Range("A" & y).value then wh1.range("B" & y).value = wsh2.range("E" & i).value "met a jour les valeurs de la wsh2 dans wsh1" wh1.range("D" & y).value = wsh2.range("B" & i).value end if next y next i
J'ai donc voulu utiliser des find pour accélérer la macro
sauf que la valeur de row_temp reste la même. Et donc ma feuille marche mondial ne se met pas à jourCode:
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 Set wsh1 = Worksheets("PV-DONNEES") Set wsh2 = Worksheets("PV - MARCHE MONDIAL") nbvalpvdonnees = 2 + wsh1.Range("E1").Value nbvalWM = wsh2.Range("N1").Value + 1 For Ligne = 2 To nbvalWM With ThisWorkbook.Sheets("PV-DONNEES") Set m = wsh1.Columns("D").Find(wsh1.Cells(Ligne, "C").Value, LookIn:=xlValues, lookat:=xlWhole) If Not m Is Nothing Then row_temp = m.Row 'Marque : ThisWorkbook.Sheets("PV - MARCHE MONDIAL").Range("B" & Ligne).Value = .Range("A" & row_temp).Value 'LOA : ThisWorkbook.Sheets("PV - MARCHE MONDIAL").Range("D" & Ligne).Value = .Range("C" & row_temp).Value 'public price : ThisWorkbook.Sheets("PV - MARCHE MONDIAL").Range("E" & Ligne).Value = .Range("E" & row_temp).Value 'price iso spec : ThisWorkbook.Sheets("PV - MARCHE MONDIAL").Range("F" & Ligne).Value = .Range("J" & row_temp).Value 'Range ThisWorkbook.Sheets("PV - MARCHE MONDIAL").Range("A" & Ligne).Value = RangeDeLOA(ThisWorkbook.Sheets("PV - MARCHE ONDIAL").Range("D" & Ligne).Value) End If End With Next Ligne Set wsh1 = Nothing Set wsh2 = Nothing Set m = Nothing
PS : Je viens de voir que je suis pas dans la bonne rubrique mais je sais pas déplacer mon post :/
Merci d'avance pour votre aide