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 :

appeler un fonction : erreur de compilation


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
    Consultant en Business Intelligence
    Inscrit en
    Juillet 2012
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant en Business Intelligence
    Secteur : Conseil

    Informations forums :
    Inscription : Juillet 2012
    Messages : 21
    Par défaut appeler un fonction : erreur de compilation
    Bonjour à tous,

    j'ai un petit problème dans mon 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
    Public k, l, m, n, o, p, q, r, s, t, u, v, w As Variant
     
    Function StatSite(NumCol)
     
    Derlig = Data.Range("A" & Rows.Count).End(xlUp).Row
    Derlig2 = Primes.Range("a" & Rows.Count).End(xlUp).Row
    Derlig3 = Report.Range("a" & Rows.Count).End(xlUp).Row
     
            k = 0
            l = 0
            For j = 2 To Derlig
                'moyenne note individuelle pour Reims
                If Data.Range("g" & j) = Hypo.Range("n3") Then
                    k = k + WorksheetFunction.VLookup(Data.Range("a" & j), Primes.Range("a6:t" & Derlig2), NumCol, False)
                'moyenne note individuelle pour Paris
                ElseIf Data.Range("g" & j) = Hypo.Range("n4") Then
                    l = l + WorksheetFunction.VLookup(Data.Range("a" & j), Primes.Range("a6:t" & Derlig2), NumCol, False)
                End If
            Next j
     
    End Function
     
    Sub Statistiques1()
    '******************************************************************************************************************************************
    'résumé statistique
    Dim Derlig, Derlig2, Derlig3 As Long
    Dim i, j As Integer
     
    'définition de la dernière ligne vide
    Derlig = Data.Range("A" & Rows.Count).End(xlUp).Row
    Derlig2 = Primes.Range("a" & Rows.Count).End(xlUp).Row
    Derlig3 = Report.Range("a" & Rows.Count).End(xlUp).Row
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'moyenne générale CRC
        Report.Range("a" & Derlig3 + 1) = "Moyenne générale du CRC"
        With Report.Range("a" & Derlig3 + 1).Font
            .Size = 11
            .Bold = True
            .Underline = True
        End With
        'nombre de CC au total
            Report.Range("b" & Derlig3 + 1) = WorksheetFunction.CountA(Primes.Range("c6:c" & Derlig2))
        'note individuelle
            Report.Range("c" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("f6:f" & Derlig2))
        'prime
            Report.Range("d" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("g6:g" & Derlig2))
        'note IVR
            Report.Range("e" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("h6:h" & Derlig2))
        'prime
            Report.Range("f" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("i6:i" & Derlig2))
        'note commerciale
            Report.Range("g" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("j6:j" & Derlig2))
        'prime
            Report.Range("h" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("k6:k" & Derlig2))
        'total prime qualité
            Report.Range("i" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("l6:l" & Derlig2))
        'prod appels
            Report.Range("j" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("m6:m" & Derlig2))
        'temps en emails
            Report.Range("k" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("o6:o" & Derlig2))
        'pondération
            Report.Range("m" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("s6:s" & Derlig2))
        'prime totale
            Report.Range("n" & Derlig3 + 1) = WorksheetFunction.Average(Primes.Range("t6:t" & Derlig2))
        'prod emails (sur personnes dont temps emails dépasse 14h)
            k = 0
            For i = 6 To Derlig2
                If Primes.Range("o" & i) > Hypo.Range("d17") Then
                    k = k + 1
                    l = l + Primes.Range("p" & i)
                End If
            Next i
            Report.Range("l" & Derlig3 + 1) = l / k
     
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'moyenne selon le site
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Report.Range("a" & Derlig3 + 3) = "Moyenne par site"
        With Report.Range("a" & Derlig3 + 3).Font
            .Size = 11
            .Bold = True
            .Underline = True
        End With
     
        Report.Range("a" & Derlig3 + 4) = "Moyenne sur le site de Reims"
        Report.Range("a" & Derlig3 + 4).Font.Underline = True
        Report.Range("a" & Derlig3 + 5) = "Moyenne sur le site de Paris"
        Report.Range("a" & Derlig3 + 5).Font.Underline = True
     
            k = 0
            l = 0
            For j = 2 To Derlig
                'nombre de CC pour Reims
                If Data.Range("g" & j) = Hypo.Range("n3") Then
                    k = k + 1
                'nombre de CC pour Paris
                ElseIf Data.Range("g" & j) = Hypo.Range("n4") Then
                    l = l + 1
                End If
            Next j
     
            Report.Range("b" & Derlig3 + 4) = k
            Report.Range("b" & Derlig3 + 5) = l
     
    'note individuelle
    StatSite (6)
    Report.Range("c" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("c" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'prime note individuelle
    StatSite (7)
    Report.Range("d" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("d" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'note IVR
    StatSite (8)
    Report.Range("e" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("e" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'prime note IVR
    StatSite (9)
    Report.Range("f" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("f" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'note commerciale
    StatSite (10)
    Report.Range("g" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("g" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'prime note commerciale
    StatSite (11)
    Report.Range("h" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("h" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'prime totale
    StatSite (12)
    Report.Range("i" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("i" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'productivité appels (ACW)
    StatSite (13)
    Report.Range("j" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("j" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'temps en emails
    StatSite (15)
    Report.Range("k" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("k" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'pondération
    StatSite (19)
    Report.Range("m" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("m" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'prime totale
    StatSite (20)
    Report.Range("n" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
    Report.Range("n" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
     
    'productivité emails (pour les CC qui ont plus de 14h de temps d'emails)
        k = 0
        l = 0
        For j = 2 To Derlig
        'moyenne prod emails pour Reims
            If Primes.Range("o" & j) > Hypo.Range("d17") Then
                If Data.Range("g" & j) = Hypo.Range("n3") Then
                    k = k + WorksheetFunction.VLookup(Data.Range("a" & j), Primes.Range("a6:t" & Derlig2), 16, faux)
                    'moyenne prod emails pour Paris
                ElseIf Data.Range("g" & j) = Hypo.Range("n4") Then
                    l = l + WorksheetFunction.VLookup(Data.Range("a" & j), Primes.Range("a6:t" & Derlig2), 16, faux)
                End If
            End If
        Next j
     
        Report.Range("l" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
        Report.Range("l" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
    end sub
    Pour simplifier encore, j'aurais aimé mettre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
        Report.Range("l" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
        Report.Range("l" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
    directement dans fonction en transformant les "l", "m", "n", etc...en paramètres.
    j'ai tenté :
    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
    Function StatSite(Lettre,NumCol)
     
    Derlig = Data.Range("A" & Rows.Count).End(xlUp).Row
    Derlig2 = Primes.Range("a" & Rows.Count).End(xlUp).Row
    Derlig3 = Report.Range("a" & Rows.Count).End(xlUp).Row
     
            k = 0
            l = 0
            For j = 2 To Derlig
                'moyenne note individuelle pour Reims
                If Data.Range("g" & j) = Hypo.Range("n3") Then
                    k = k + WorksheetFunction.VLookup(Data.Range("a" & j), Primes.Range("a6:t" & Derlig2), NumCol, False)
                'moyenne note individuelle pour Paris
                ElseIf Data.Range("g" & j) = Hypo.Range("n4") Then
                    l = l + WorksheetFunction.VLookup(Data.Range("a" & j), Primes.Range("a6:t" & Derlig2), NumCol, False)
                End If
            Next j
     
        Report.Range("Lettre" & Derlig3 + 4) = k / (Report.Range("b" & Derlig3 + 4))
        Report.Range("Lettre" & Derlig3 + 5) = l / (Report.Range("b" & Derlig3 + 5))
    End Function
    mais quand j'appelle
    StatSite(c, 6) par exemple, j'ai "ERREUR DE COMPILATION : ATTENDU : ="
    si ce n'était que ça, je me passerai de cette simplification, mais je vais avoir besoin de créer des fonctions avec divers paramètres dans d'autres macros à venir et j'aimerais comprendre le problème.
    j'ai cherché sur internet, mais ça n'a pas été très fructueux.

    si l'un/l'une d'entre vous peut m'aider !

    merci

  2. #2
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    bonjour,

    en VB si ta fonction ne retourne rien , ce qui semble être ton cas on utilise une "Sub" .. remplace Function par sub ..

    pour l'appel supprime les parenthèses .

  3. #3
    Membre averti
    Femme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Juillet 2012
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant en Business Intelligence
    Secteur : Conseil

    Informations forums :
    Inscription : Juillet 2012
    Messages : 21
    Par défaut
    mais dans ce cas, il faut que je définisse
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (Report.Range("b" & Derlig3 + 5))
    avant, non ? sinon il ne comprend pas ce que c'est.
    parce que si j'éxécute le code tel qu'il est là en transformant ma fonction en procédure, il lit la première procédure qui sera appelée dans la seconde.

    je ne sais pas si je suis claire...

Discussions similaires

  1. Réponses: 12
    Dernier message: 12/05/2006, 10h21
  2. Erreur de compilation -> appel de fonction
    Par R'SKaP dans le forum C++
    Réponses: 2
    Dernier message: 04/12/2005, 02h33
  3. Réponses: 1
    Dernier message: 22/11/2005, 18h19
  4. [appel de fonction]Erreur bizarre
    Par DEC dans le forum ASP
    Réponses: 4
    Dernier message: 10/08/2004, 18h08

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