Macro trop lente

JBARBE

XLDnaute Barbatruc
Bonsoir à tous,
Ma macro suivante est trop longue !
Pouvez-vous y remédier ?
Merci à l'avance et bonne nuit !

Code:
Sub Supprimer_Zero()
Dim i As Long, j As Long, derniere_ligne As Long
Application.ScreenUpdating = False
With Sheets(1)
derniere_ligne = Range("A1" ).End(xlDown).Row 'Dernière ligne de la base de données
For i = 1 To derniere_ligne
For j = 1 To 40
If .Cells(i, j) = 0 And .Cells(i, j).Interior.ColorIndex = xlNone Then .Cells(i, j) = ""
Next j
Next i
End With
Application.ScreenUpdating = True
End Sub
 

Pièces jointes

  • Essai_Zero.xls
    110 KB · Affichages: 26

Dranreb

XLDnaute Barbatruc
Bonsoir.
Il semble qu'il y ait un peu de mieux comme ça, mais ça ne va pas s'il y a des formules qui doivent rester :
VB:
Sub Supprimer_Zero()
Dim Plage As Range, Cel As Range, T(), L&, C&
'Sheets(1).[A1:AN10000].Value = 0: End
Application.ScreenUpdating = False
Set Plage = Application.Range(Sheets(1).[AN1], Sheets(1).[A65536].End(xlUp))
T = Plage.Value
For L = 1 To UBound(T, 1): For C = 1 To UBound(T, 2)
   If T(L, C) = 0 Then If Plage(L, C).Interior.ColorIndex = xlNone Then T(L, C) = Empty
   Next C, L
Plage.Value = T
Application.ScreenUpdating = True
End Sub
Dommage qu'il faille tester .Interior.ColorIndex, car ça empêche d’accélérer davantage.
Selon le cas de figure réel il peut y avoir aussi quelque chose à faire avec SpecialCells…
 

Discussions similaires

Statistiques des forums

Discussions
312 104
Messages
2 085 332
Membres
102 863
dernier inscrit
Selemani