Bonjour,
Je trouve ma macro trop longue : 2.25... secondes
Sub essai()
Dim Ws As Worksheet
Dim Wsh As Worksheet
Dim MoisEnCours As Integer
Dim AnneeEnCours As Integer
Dim Ligne As Integer
Dim Col As Integer
Dim Cel As Range
Dim x As Range
Dim start As Single
start = Timer
Application.ScreenUpdating = False
Set Ws = Worksheets("Machin")
Set Wsh = Worksheets("Truc")
MoisEnCours = Month(Date)
AnneeEnCours = Year(Date)
NomDuMois = MonthName(MoisEnCours)
Set x = Ws.Range("B1:M1").Find(MoisEnCours, , xlValues, xlWhole, , , False) 'initialise la variable objet x de la plage B1:M1 qui contient le numéro du mois en cours
For Each Cel In Ws.Range("A17:A28")
LigCel = Cel.Row
For Each Cat In Wsh.Range("F2:F9999")
ligcat = Cat.Row
If Wsh.Cells(ligcat, 1) = AnneeEnCours And Wsh.Cells(ligcat, 2) = NomDuMois Then
If Wsh.Cells(ligcat, 6) = Cel Or Wsh.Cells(ligcat, 7) = Cel Then
Montant = Wsh.Cells(ligcat, 5)
If Not x Is Nothing Then ' signifie est-ce que ma variable x représente la cellule correspondant au n° du mois en cours
' MsgBox x.Column
Col = x.Column ' définit la colonne contenant la variable x
If Ws.Cells(LigCel, 1) Like Cel Then
Cells(LigCel, 15).Clear
If Cells(LigCel, Col) = "" Then
Cells(LigCel, 15) = Montant
End If
End If
End If
End If
End If
Next Cat
Next Cel
Set x = Nothing
Set Ws = Nothing
Set Wsh = Nothing
MsgBox "durée du traitement: " & Timer - start & " secondes"
End Sub
y a-t-il moyen de faire moins long ?
Daniel