Bonjour le forum,
Je sèche sur un bout de code simple, mais très lent, et je ne comprends pas pourquoi.
Dans une feuille A, j'ai une liste de numéro de commandes, et j'effectue une recherche sur une autre feuille B afin de ramener des infos en face des numéros de commande de la feuille A.
Le fichier contient en gros 6000 lignes, ce qui n'est pas énorme. Pourtant, ce code prend pratiquement 30 minutes.
Le plus étrange pour moi est que quand je ne rapporte que le premier range d'infos (entre B et I plus tôt), je n'en ai que pour une vingtaine de secondes.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 Dim WsRecap As Worksheet, WsComm As Worksheet, PlageCdes As Range, C As Range Dim i As Long Set WsRecap = Sheets("Récap") Set WsComm = Sheets("Commandes") Set PlageCdes = WsComm.Range("A4:A" & WsComm.[A65536].End(xlUp).Row) Application.ScreenUpdating = False For i = 4 To WsRecap.[A65536].End(xlUp).Row If Len(WsRecap.Cells(i, 14)) <> 8 Then With PlageCdes Set C = .Find(WsRecap.Cells(i, 1), lookat:=xlWhole) If Not C Is Nothing Then WsComm.Range("B" & C.Row & ":I" & C.Row).Copy Destination:=WsRecap.Cells(i, 2) WsComm.Range("O" & C.Row & ":Q" & C.Row).Copy Destination:=WsRecap.Cells(i, 14) End If End With End If Next i Application.ScreenUpdating = True End Sub
Et quand j'essaie de ramener le range "O:Q", je me traîne la-men-table-ment.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Application.ScreenUpdating = False For i = 4 To WsRecap.[A65536].End(xlUp).Row If Len(WsRecap.Cells(i, 14)) <> 8 Then With PlageCdes Set C = .Find(WsRecap.Cells(i, 1), lookat:=xlWhole) If Not C Is Nothing Then WsComm.Range("B" & C.Row & ":I" & C.Row).Copy Destination:=WsRecap.Cells(i, 2) End If End With End If Next i Application.ScreenUpdating = True End Sub
Et ça commence à me rendre chèvre.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Application.ScreenUpdating = False For i = 4 To WsRecap.[A65536].End(xlUp).Row If Len(WsRecap.Cells(i, 14)) <> 8 Then With PlageCdes Set C = .Find(WsRecap.Cells(i, 1), lookat:=xlWhole) If Not C Is Nothing Then WsComm.Range("O" & C.Row & ":Q" & C.Row).Copy Destination:=WsRecap.Cells(i, 14) End If End With End If Next i Application.ScreenUpdating = True End Sub
Partager