IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Execution d'une macro est très lente


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    informatique pour,l'entreprise
    Inscrit en
    Avril 2011
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : informatique pour,l'entreprise
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2011
    Messages : 18
    Par défaut
    Bonjour,

    Je tente de faire des macros mais elle prend trop de temps.
    toutes c'est macros je le mets dans un bouton pour faire des calculs mais ça prend beaucoup de temps,
    le but de c'est macros et le suivant:
    1 étape : un filtrage par date je fais copier quelque colonne dans j'ai besoin
    2 étape : je fais la création d'un TCD pour inversé une colonne a une ligne
    3 étape : après je fais copier les données inversé dans un autre tableau pour faire des calcules aussi de faire le trie et finalement de les copier dans un autre tableau pour l'affichage
    Je sais que c'est un peu répétitif car je suis débutante en VBA, s'il vous plait c'est vous avez une idée pour minimisé un peu le traitement j'aimerais bien.

    voila le code:
    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
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
     Sub copyAct()
     
    Dim ws As Worksheet
    Dim i As Integer
    'set worksheet variable
    Set ws = Sheet4
     
    With ws
        .Range("DataScrapCopy01").Select
        Selection.copy
        .Range("AG9").Select
        ActiveSheet.Paste
    .Range("AI9") = WorksheetFunction.sum(Range("AC9:AE9"))
     
    For i = 9 To .Range("AC" & Rows.Count).End(xlUp).Row
        .Range("AI" & i) = WorksheetFunction.sum(Range("AC" & i & ":AE" & i))
    Next i
     
    End With
    End Sub
     
    Sub create_TCD()
    'Dimension des variables
     
    Dim wshTCD      As Worksheet
    Dim pvtTCD      As PivotTable
     
       'Affectation du TCD à la feuille "TCD automatique"
        Set wshTCD = Worksheets("DataScrap")
        On Error Resume Next
    Application.ScreenUpdating = False
       'Suppression de tous les TCD existants dans la feuille
        For Each pvtTCD In wshTCD.PivotTables
            pvtTCD.TableRange2.Clear
        Next pvtTCD
     
       'Ajout d'un TCD sur la feuille "TCD automatique"
        Set pvtTCD = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Echange") _
                    .CreatePivotTable(tabledestination:=wshTCD.Range("AK8"), TableName:="pivo1")
     
       'Ajout des champs au TCD
           With pvtTCD
     
            'Ajout d'une Ligne
            With .PivotFields("Machine")
                .Orientation = xlColumnField
                .Position = 1
            End With
     
            'Ajout d'une Colonne
            With .PivotFields("Shift")
                .Orientation = xlRowField
                .Position = 1
            End With
     
            'Ajout d'une Valeur Cotisation
            With .PivotFields("Defaut")
                .Orientation = xlDataField
            End With
        End With
         ActiveSheet.PivotTables("pivo1").ColumnGrand = False
         ActiveSheet.PivotTables("pivo1").RowGrand = False
     
       wshTCD.Range("FinalEchange").Select
        Selection.copy
        wshTCD.Range("AW9").Select
        ActiveSheet.Paste
     
        Application.ScreenUpdating = True
    'error block
    On Error GoTo 0
    End Sub
     
    Sub calculScrapshift1()
     
    Dim ws As Worksheet
    Const SourceColumn As String = "AX"
    Const DestColumn As String = "BA"
    Const TotalCell As String = "somTotal"
    Dim i As Long
    Dim DernLigne As Long
    Application.ScreenUpdating = False
    DernLigne = Range("AX" & Rows.Count).End(xlUp).Row
     
    On Error Resume Next
    Set ws = Sheet4
    With ws
     
       For i = 9 To DernLigne
            Range("BA" & i).Formula = "=(" & "AX" & i & "/" & TotalCell & ")*100"
            Columns("BA").NumberFormat = "0.00"
     Next i
    Application.ScreenUpdating = True
     
    End With
    On Error GoTo 0
     
    End Sub
     
    Sub calculScrapshift2()
     
    Dim ws As Worksheet
    Const SourceColumn As String = "AY"
    Const DestColumn As String = "BB"
    Const TotalCell As String = "somTotal"
    Dim i As Long
    Dim DernLigne As Long
    Application.ScreenUpdating = False
    DernLigne = Range("AY" & Rows.Count).End(xlUp).Row
     
    On Error Resume Next
    Set ws = Sheet4
    With ws
     
       For i = 9 To DernLigne
            Range("BB" & i).Formula = "=(" & "AY" & i & "/" & TotalCell & ")*100"
            Columns("BB").NumberFormat = "0.00"
     Next i
     
    End With
    Application.ScreenUpdating = True
    On Error GoTo 0
     
     
    End Sub
     
     
    Sub calculScrapshift3()
     
    Dim ws As Worksheet
    Const SourceColumn As String = "AZ"
    Const DestColumn As String = "BC"
    Const TotalCell As String = "somTotal"
    Dim i As Long
    Dim DernLigne As Long
    Application.ScreenUpdating = False
    DernLigne = Range("AZ" & Rows.Count).End(xlUp).Row
     
    On Error Resume Next
    Set ws = Sheet4
    With ws
     
       For i = 9 To DernLigne
            Range("BC" & i).Formula = "=(" & "AZ" & i & "/" & TotalCell & ")*100"
            Columns("BC").NumberFormat = "0.00"
     Next i
    Application.ScreenUpdating = True
     
    End With
    On Error GoTo 0
     
    End Sub
     
    Sub somTotalScrap()
     
    Dim ws As Worksheet
    Dim i As Integer
    Dim derli As Long
     
    ' sheet variable
    Set ws = Sheet4
    With ws
    Application.ScreenUpdating = False
    Range("BD9") = WorksheetFunction.sum(Range("BA9:BC9"))
     
    For i = 9 To Range("BA" & Rows.Count).End(xlUp).Row
        Range("BD" & i) = WorksheetFunction.sum(Range("BA" & i & ":BC" & i))
    Next i
    Application.ScreenUpdating = True
    End With
     
    End Sub
     
    Sub MaxScrap()
     
    On Error Resume Next
    Application.ScreenUpdating = False
        Range("AW8:BE38").Select
        ActiveWorkbook.Worksheets("DataScrap").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("DataScrap").Sort.SortFields.Add Key:=Range( _
            "BD9:BD38"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("DataScrap").Sort
            .SetRange Range("AW8:BE38")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Application.ScreenUpdating = True
    On Error GoTo 0
     
    End Sub
     
     
    Sub calculatCumuleScrap()
     
    On Error Resume Next
    Dim ws As Worksheet
    Dim VisRng As Range, c As Range
    Dim StartRow As Long
    Dim LastRow As Long
     
    Set ws = Sheet4
     
    With ws
    Application.ScreenUpdating = False
        LastRow = .Cells(.Rows.Count, "BD").End(xlUp).Row '<-- get last row with data in Column K
     
        StartRow = 9 '<-- init value
     
         ' set visible range to only filtered cells in Column G
        Set VisRng = .Range(Range("BD" & StartRow), Range("BD" & LastRow)).SpecialCells(xlCellTypeVisible)
     
        StartRow = VisRng.Item(1).Row '<-- update first row in visible range
     
        For Each c In VisRng
            If c.Row = StartRow Then
     
                .Range("BE" & c.Row) = .Range("BD" & c.Row).Value
            Else
                .Range("BE" & c.Row).Formula = "=SUBTOTAL(9,BD" & StartRow & ":BD" & c.Row & ")"
            End If
        Next c
    .Columns("BE").NumberFormat = "0.00"
    Application.ScreenUpdating = True
    End With
     
    On Error GoTo 0
     
     
    End Sub
     
    Sub copyScrapFinal()
     
    'error handler
    On Error Resume Next
    Application.ScreenUpdating = False
        Sheet4.Activate
        Range("graphiq,graphiqu,grafiquu").Select
        Selection.copy
        Range("BG9").Select
        ActiveSheet.Paste
        Application.ScreenUpdating = True
    'error block
        On Error GoTo 0
    End Sub
    Est ce que vous pouvez m'aider par rapport à mon cas?

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Chaque select provoque un événement!
    .Range("DataScrapCopy01").copy .Range("AG9") !

    Intéressés toi a formulaR1C1!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    range("A1:A123").formulaR1C1="=Sum(Rc[10]:Rc[15])"
    range("A1:A123").value=range("A1:A123").value

Discussions similaires

  1. [2.x] symfony,ajax c'est très lent avec une route pour keyup
    Par cuscodkr dans le forum Symfony
    Réponses: 22
    Dernier message: 27/11/2015, 17h40
  2. execution d'une macro
    Par driss23 dans le forum Access
    Réponses: 2
    Dernier message: 27/04/2006, 11h57
  3. [VBA-E]Execution d'une macro access sous excel VBA
    Par virtualinsanity dans le forum Macros et VBA Excel
    Réponses: 19
    Dernier message: 21/04/2006, 17h27
  4. [VBA-E]Pendant l'execution d'une macro
    Par benoue dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 17/03/2006, 18h28
  5. execution d'une macro d'access sous delphi
    Par galendor_d'ambre dans le forum Bases de données
    Réponses: 6
    Dernier message: 10/02/2004, 15h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo