Code qui ne fonctionne qu'avec un command button
Bonjour, je voudrai vous poser une petite question. J'ai ce code qui devrait se déclencher à la fermeture du fichier mais malheureusement, il ne s'applique pas ni ne provoque d'erreur d'ailleurs. Seulement il n'entraîne aucun évènement comme si il n'existait pas. Alors que si je copie colle ce code et l'applique à la pression d'un command button, il marche correctzement avait vous une explication ?
Code:
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
| Dim ws1 As Worksheet, ws2 As Worksheet
Dim Lws1 As Integer, Lws2 As Integer
Dim VC As String, VT As Range
Dim suivant As Boolean
Set ws1 = Worksheets("Factures mobilisées")
Set ws2 = Worksheets("Archives régularisations")
For o = 2 To Lws1
ws1.Range("Z" & o).FormulaR1C1 = "=CONCATENATE(RC[-24],RC[-23])"
Next o
Lws1 = ws1.Cells(Rows.Count, 26).End(xlUp).Row
Lws2 = ws2.Cells(Rows.Count, 26).End(xlUp).Row
suivant = False
Do While Lws1 > 1
VC = ws1.Cells(Lws1, 26) 'valeur à chercher
Do
With ws1
'verifier si la valeur est dans la feuille 1
Set VT = .Range("Z2:Z" & Lws1 - 1).Find(VC, LookIn:=xlValues, lookAt:=xlWhole)
If Not VT Is Nothing Then 'si on la trouve au dessus
.Rows(VT.Row & ":" & VT.Row).Delete Shift:=xlUp 'on supprime la ligne
Lws1 = Lws1 - 1 '
suivant = True ' on en cherche un autre
Else
suivant = False 'il n'y en a plus -> sortir de la boucle
End If
End With
Loop While suivant = True And Lws1 > 1
'idem en verifiant dans la feuille 2 si la valeur est dans la feuille 2
If Not ws2.Range("Z2:Z" & Lws2).Find(VC, LookIn:=xlValues, lookAt:=xlWhole) Is Nothing Then _
ws1.Rows(Lws1 & ":" & Lws1).Delete Shift:=xlUp
Lws1 = Lws1 - 1
Loop
Set ws1 = Nothing
Set ws2 = Nothing
Set VT = Nothing |
Merci beaucoup d'avance à ceux qui pourront m'aider à comprendre ;)