Blocage avec un Iserror

Bonjour voici mon code,

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

Ca bloque a ce niveau la

            If WorksheetFunction.IsErr(WorksheetFunction.Match(SerieDate(i), Range("Quotation").Resize(, j * 2 + 1), 0)) = False Then

Ci-joint le lien du fichier: https://docs.google.com/open?id=0B1XYA-Rihjk3OGJzNWFJYktRb0E

Pourriez vous m'aider?

Je vous remercie!!

J'ai cette erreur en fait

Run-time error '1004'

Method 'Range' of object '_Global' failed

Bonjour

A mon avis plusieurs erreurs

Remplaces WorksheetFunction par Application

Vérifies ta zone nommée "Quotation" (manque "NbDate" et "NbStocks")

Comme je ne sais pas ce que tu veux faire

essayes ca déjà

Bonjour Banzai

Mais ce n'est pas encore résolu...

Bonjour

J'ai modifié ma réponse

C'est pas bon si j'ai mis ca?

NbDate = Range("DateFin").Value - Range("DateDeb").Value + 1
NbStocks = Range("Stocks").Rows.Count

ainsi que

ActiveWorkbook.Names.Add Name:="Quotation", RefersToR1C1:="=offset('Sheet1'!R4C3,,,NbDate,NbStocks*2)"

En fait c'est un peu tiré par les cheveux

Je voudrais que par exemple pour le stock GSZ FP lorsque avant sa date de cotation, au lieu de mettre un NA, je voudrais la formule suivante dans les cellules correspondant a GSZ FP pour les dates anterieures a sa cotation

($Cours de GSZ FP a sa premiere date de cotation$ / $Cours de XOM US a la premiere date de cotation de GSZ FP$) * Cours de XOM a la date en question.

Sinon, dès que GSZ FP cote, donc a partir du 7/7/2005, on prend son cours.

Petite illustration

La partie bleue represente la periode ou GSZ FP est deja introduite donc on mets tout simplement son cours..

La partie verte represente la periode avant le debut de cotation de GSZ FP donc il faudrait mettre la formule definie ci-dessus

Merci pour ton aide!

Bonsoir,

C'est ça que tu appelles un fichier mis à jour ?

Un vrai fichier avec le code contenant tes dernières modifs serait plus utile...

eric

Bonjour

Je ne comprends pas tout ce que tu veux faire

En Sheet1 il n'y a pas de #N/A

En Sheet3 il y en a

C'est pour cette page que j'ai développé la macro

A vérifier si j'ai compris

PS:

au passage ESTERR() ne teste pas les #N/A contrairement à ESTERREUR().

eric

Salut Banzai

Merci pour ton aide

ta macro fait une erreur ici

            If WorksheetFunction.IsErr(WorksheetFunction.Match(SerieDate(i), Range("Quotation").Resize(, J * 2 + 1), 0)) = False Then

à croire que je suis transparent...

ohhh mille excuses!!!!

Bonjour

remy444 a écrit :

ta macro fait une erreur ici

C'est ta macro

La mienne est dans un autre module et est complètement différente

Je t'ai dis que je ne comprends pas que tu travailles sur la Sheet1 alors qu'elle ne contient pas d'erreur contrairement à Sheet3

Rechercher des sujets similaires à "blocage iserror"