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 :

Run-time error '1004'


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Novembre 2012
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Novembre 2012
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Run-time error '1004'
    Bonjour a tous;
    J'ai cette erreur
    Run-time error '1004'
    Method 'Range' of object '_Global' failed


    Avec le code suivant
    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
    Sub copydatabis()
    Dim Nom As Variant
    Dim NomStk(), SerieDate()
     
    'Suppression des noms des plages
        For Each Nom In ActiveWorkbook.Names
            If Nom.Name = "Stocks" Or Nom.Name = "DateDeb" Or Nom.Name = "DateFin" Then
                Nom.Delete
            End If
        Next
     
    'Réinitialisation des plages Nom
        ActiveWorkbook.Names.Add Name:="Stocks", RefersToR1C1:="=offset('Sheet1'!R4C1,1,,counta('Sheet1'!C1)-3,1)"
        ActiveWorkbook.Names.Add Name:="DateDeb", RefersToR1C1:="=R1C2"
        ActiveWorkbook.Names.Add Name:="DateFin", RefersToR1C1:="=R2C2"
     
    NbDate = Range("DateFin").Value - Range("DateDeb").Value + 1
    NbStocks = Range("Stocks").Rows.Count
     
        ActiveWorkbook.Names.Add Name:="Quotation", RefersToR1C1:="=offset('Sheet1'!R4C3,,,NbDate,NbStocks*2)"
     
     
    'Initialisation de la variable tableau NomStk
    Cmpt = 0
    For Each cell In Range("Stocks").Cells
        ReDim Preserve NomStk(Cmpt)
        NomStk(Cmpt) = cell.Value
        Cmpt = Cmpt + 1
    Next cell
     
    'Initialisation de la variable tableau NomRef
    Cmpt = 0
    ReDim NomRef(UBound(NomStk, 1))
    For i = 0 To UBound(NomStk, 1)
        NomRef(i) = Range("Stocks").Cells(i + 1).Offset(0, 1).Value
    Next i
     
    'Initialisation de la série des dates jours ouvrés
    Cmpt = 0
    For i = Range("DateDeb").Value To Range("DateFin").Value
        If WorksheetFunction.Weekday(CDate(i) < 7) Or WorksheetFunction.Weekday(CDate(i) > 1) Then
            ReDim Preserve SerieDate(Cmpt)
            SerieDate(Cmpt) = CDate(i)
            Cmpt = Cmpt + 1
        End If
    Next i
     
    'Compte le nombre de valeur <> "" dans le vecteur NomRef
    Cmpt = 0
    For i = 0 To UBound(NomRef)
        If NomRef(i) <> "" Then Cmpt = Cmpt + 1
    Next i
     
    'Initialisation de la table des résultats
    ReDim Returns(UBound(SerieDate), UBound(NomStk) - Cmpt)
     
    'Resultats
     
    For i = 0 To UBound(SerieDate)
        For j = 0 To UBound(NomStk)
            Cmpt = 0
            For k = 0 To UBound(NomRef)
                If NomStk(j) = NomRef(k) Then Cmpt = Cmpt + 1
            Next k
            If NomRef(j) = "" And Cmpt = 0 Then
                If WorksheetFunction.IsErr(WorksheetFunction.Match(SerieDate(i), Range("Quotation").Resize(, j * 2 + 1), 0)) = False Then
                    LigStk = WorksheetFunction.Match(SerieDate(i), WorksheetFunction.Index(Range("Quotation"), 0, j * 2 + 1), 0)
                    Returns(i, j) = WorksheetFunction.Index(Range("Quotation"), LigStk, j * 2 + 2)
                Else
                    Returns(i, j) = 0
                End If
            Else
                DateLunch = WorksheetFunction.Index(Range("Quotation"), 1, j * 2 + 1)
                RetStk = WorksheetFunction.Index(Range("Quotation"), 1, j * 2 + 2)
                For k = 0 To UBound(NomStk)
                    If NomRef(j) = NomStk(k) Then ColRef = k
                Next k
                LigRef = WorksheetFunction.Match(DateLunch, WorksheetFunction.Index(Range("Quotation"), 0, ColRef * 2 + 1), 0)
                RetRef = WorksheetFunction.Index(Range("Quotation"), LigRef, ColRef * 2 + 2)
                LigRef = WorksheetFunction.Match(SerieDate(i), WorksheetFunction.Index(Range("Quotation"), 0, ColRef * 2 + 1), 0)
                 Returns(i, j) = RetSk / RetRef * WorksheetFunction.Index(Range("Quotation"), LigRef, ColRef)
            End If
        Next j
    Next i
     
    End Sub
    Il surligne en jaune la ligne suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If WorksheetFunction.IsErr(WorksheetFunction.Match(SerieDate(i), Range("Quotation").Resize(, j * 2 + 1), 0)) = False Then
    Voici le fichier
    https://docs.google.com/open?id=0B1X...GJzNWFJYktRb0E

    Merci beaucoup pour votre aide!!

  2. #2
    Expert éminent Avatar de jfontaine
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Juin 2006
    Messages
    4 754
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Contrôleur de Gestion

    Informations forums :
    Inscription : Juin 2006
    Messages : 4 754
    Points : 9 396
    Points
    9 396
    Par défaut
    Bonjour,

    Cette erreur intervient quand WorksheetFunction retourne une erreur de calcul (#NA, #VALUE, etc ...)

    Une parade avec Resume Next
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    On Error Resume Next
    If WorksheetFunction.IsErr(WorksheetFunction.Match(SerieDate(i), Range("Quotation").Resize(, j * 2 + 1), 0)) = False Then
    ...
    End If
     
    On error Goto 0

Discussions similaires

  1. [XL-2010] Run time error 1004 Application defined or object defined
    Par AmbreM dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 19/09/2013, 18h00
  2. Run time error 1004 - Select method class failed
    Par fhuyet dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 08/07/2008, 11h18
  3. Excel 2003 - Run-time error '1004'
    Par GuyRo dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 08/05/2008, 10h20
  4. [VBA-E] Run-time error 1004, pourquoi ?
    Par Capsule dans le forum Macros et VBA Excel
    Réponses: 18
    Dernier message: 25/01/2007, 22h12
  5. Excel - macro (format conditionnel - run-time error 1004)
    Par Chewi dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 01/09/2006, 19h18

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