Excel - Demande d'aide pour alléger Macro

Résolu
Bonjour,

J'utilise excel 2011. Qqn m'avait fait une macro fonctionnant sous Windows.
Depuis 2011 je l'utilise directement sur Mac. Je sais qu'Excel est de tte manière plus lent que sous Windows. Mais là... La macro met un temps hallucinant à faire le tour (Ce sont de gros fichiers).

J'ai lu à droite et à gauche qu'elle pouvait être optimisé pour être plus rapide sur Mac. Qu'il peut y avoir des problèmes de redondances etc... Le soucis c'est que j'y comprends rien. Visual basic c'est du chinois...
J'ai lu par exemple que l'on pouvait insérer au début ceci:

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


Mais je ne sais pas où exactement. Je suis incapable de toucher à quoi que ce soit. Donc si qqn peut y jeter un oeil merci.

Sub Macro1()
    Set wzone = Selection.CurrentRegion
    wzone.Borders(xlDiagonalDown).LineStyle = xlNone
    wzone.Borders(xlDiagonalUp).LineStyle = xlNone
    With wzone.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
        
    i = 1
    wzone(i, 1).Select
    While i <= wzone.Rows.Count
        Set zonedeb = wzone(i, 1)
        While wzone(i, 1) = wzone(i + 1, 1)
            i = i + 1
        Wend
        Range(zonedeb, wzone(i, wzone.Columns.Count)).Select
            Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        i = i + 1
    Wend
    Range("A1").Select
End Sub


3 réponses

  • Votes
  • Date
  • Date décroissante
  1. Contributeur
    Bonjour

    Sub Macro1()
        Application.ScreenUpdating = False
        Application.Calculation = xlManual
        '
        ' le reste du programme
        '
        Application.ScreenUpdating = True
        Application.Calculation = xlAutomatic
    End Sub 

    eric

    Jamais tu ne répondras à un mp non sollicité...
    Bon, ça c'est fait.
    1. O_o

      Ha ou effectivement rien à voir ...

      Merci !
      1. Contributeur
        Je n'avais pas regardé ton code mais tu as une boucle et des .select chronophages et inutiles dedans.
        Essaie avec :
        Sub Macro3()
            Application.ScreenUpdating = False
            With Selection.CurrentRegion
                .Borders(xlDiagonalDown).LineStyle = xlNone
                .Borders(xlDiagonalUp).LineStyle = xlNone
                With .Borders(xlEdgeLeft)
                    .LineStyle = xlContinuous
                    .Weight = xlMedium
                    .ColorIndex = xlAutomatic
                End With
                With .Borders(xlEdgeTop)
                    .LineStyle = xlContinuous
                    .Weight = xlMedium
                    .ColorIndex = xlAutomatic
                End With
                With .Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .Weight = xlMedium
                    .ColorIndex = xlAutomatic
                End With
                With .Borders(xlEdgeRight)
                    .LineStyle = xlContinuous
                    .Weight = xlMedium
                    .ColorIndex = xlAutomatic
                End With
                .Borders(xlInsideVertical).LineStyle = xlNone
                With .Borders(xlInsideHorizontal)
                    .LineStyle = xlContinuous
                    .Weight = xlMedium
                    .ColorIndex = xlAutomatic
                End With
                .Interior.ColorIndex = xlNone
            End With
            Application.ScreenUpdating = True
        End Sub

        eric
    2. En fait il doit manquer quelque chose.
      Ma macro fait un cadre gras autour des prospects sur tte la longueur.
      Si la case A1 est identique à A2 elle élargit le cadre pour les englober.

      La tienne ne prend pas en compte cette dernière partie. Elle encadre juste chaque ligne sans se soucier si A1=A2

      Je ne sais pas si je suis clair