Erreur d'exécution '13' : Incompatibilité de type

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Jeremouse1

XLDnaute Nouveau
Bonjour,

j'ai une grosse base de données à partir de laquelle je voudrais extraire une date (pour faire simple). Cependant lorsque j'exécute ma macro, j'ai une erreur 13 avec une incompatibilité de type. Les lignes mises en cause par Excel lors du débogage sont les suivantes :

cel = c.Find(cel.Value, After:=cel, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

Est ce que vous arriveriez à détecter l'erreur dans cet extrait ? Sinon je peux vous copier la macro toute entière.

Cordialement,

Jeremouse1
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Bonjour,

la méthode "Find" renvoyant un OBJET de type "range", il y a lieu de faire précéder d'un "Set" et de déclarer la dite variable :
Code:
Dim cel As Range
Set cel = c.Find(cel.Value, After:=cel, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
bonne journée
@+

Edition : supposant que "c" soit bien initialisé, par contre comprends pas ceci "cel.Value, After:=cel"
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Bonsour®
Bonjour,

j'ai une grosse base de données à partir de laquelle je voudrais extraire une date (pour faire simple). Cependant lorsque j'exécute ma macro, j'ai une erreur 13 avec une incompatibilité de type. Les lignes mises en cause par Excel lors du débogage sont les suivantes :

cel = c.Find(cel.Value, After:=cel, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

Est ce que vous arriveriez à détecter l'erreur dans cet extrait ? Sinon je peux vous copier la macro toute entière.

Cordialement,

Jeremouse1

😎
Non ...
Que contient : cel.value ?
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Merci tout d'abord pour vos réponses. Pierrot93 j'ai essayé de rajouter le set devant cel (dim cel As range a été ajouté plus haut dans la macro) mais cela n'a pas marché, j'ai toujours la même erreur. Voici le code de la partie entière :



' we are at the start. we make a list of all NI1.
i = 1
Do While NI1hdr.Offset(i, 0).Value = vbNullString 'loop until we find a non-empty cell (should be quick)
i = i + 1
If i = lastcel.Row Then MsgBox "No non-empty cells in the NI1 column: exiting macro now.": Exit Sub
Loop

ReDim Preserve NI1(0 To 0)
ReDim Preserve NI1tmp(0 To 0)

i = 0
MaxNbPack = 0
For Each cel In Range("I" & NI1hdr.Row + 1, "I" & lastcel.Row)

If cel Is Nothing Then Resume Next

isinarray = False

For k = LBound(NI1tmp) To UBound(NI1tmp)
If NI1tmp(k) = cel.Value Then isinarray = True 'check if NI1 is in the tmp array which mirrors the real one
Next k

j = 0
If (Not isinarray) And cel.Value <> "" Then 'copy the NI1 to the array in i-th position


'fill the pack array, then later assign it to the NI1 array
ReDim Preserve pack(0 To j)
pack(0) = cel.Value
j = j + 1

ReDim Preserve pack(0 To j)
pack(j) = packhdr.Offset(cel.Row - firstrow + 1, 0).Value 'put the first found value into the first box
firstfindrow = cel.Row

Set c = Range(NI1hdr.Offset(1, 0), NI1hdr.Offset(lastcel.Row, 0))

Set cel = c.Find(cel.Value, After:=cel, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

Do

If cel Is Nothing Then Exit Do
isinarray = False
For k = 1 To j
If packhdr.Offset(cel.Row - firstrow + 1, 0).Value = pack(k) Then isinarray = True 'check if packhdr.value is in NI1(i, j)
Next k

If Not isinarray Then
j = j + 1
ReDim Preserve pack(0 To j)
pack(j) = packhdr.Offset(cel.Row - firstrow + 1, 0).Value
End If
Set cel = c.FindNext(cel) 'find next row with the current NI1
Loop While cel.Row <> firstfindrow

If j > MaxNbPack Then MaxNbPack = j

ReDim Preserve packtmp(0 To i)
packtmp(i) = j

ReDim Preserve NI1(0 To i)
NI1(i) = pack

ReDim Preserve NI1tmp(0 To i)
NI1tmp(i) = NI1(i)(0)

i = i + 1
End If

Next cel

nbNI1 = i - 1

Est ce que vous voyez mieux d'où peut venir l'erreur ? Si néscéssaire je peux vous envoyer la macro complète par message privé.

Cordialement,

Jeremouse1
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Ha oui pardon, en fait moi non plus je ne comprends pas bien cette fonction. En la supprimant cela à l'air de fonctionner, savez vous à quoi correspond cette fonction en temps normal ?

Cordialement,

Jeremouse1
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Bonjour,

Tu mets du Cel partout. Attention à l'hypertension ! 😛
Essaies en remplaçant cette partie (non testé).
Code:
            Set Plage = Range(NI1hdr.Offset(1, 0), NI1hdr.Offset(lastcel.Row, 0))
            Set C = Plage.Find(cel.Value, After:=cel, LookIn:=xlFormulas, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
            Do
                If C Is Nothing Then Exit Do
                isinarray = False
                For k = 1 To j
                    If packhdr.Offset(C.Row - firstrow + 1, 0).Value = pack(k) Then isinarray = True 'check if packhdr.value is in NI1(i, j)
                Next k
                If Not isinarray Then
                    j = j + 1
                    ReDim Preserve pack(0 To j)
                    pack(j) = packhdr.Offset(C.Row - firstrow + 1, 0).Value
                End If
                Set C = Plage.FindNext(C) 'find next row with the current NI1
            Loop While C.Row <> firstfindrow

A+
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Merci frangy pour ta réponse mais pour la variable Plage que tu me demandes de créer, je dois déclarer Dim Plage As Range c'est bien ça ? Quel type je dois mettre pour C ?

Cordialement,

Jeremouse1
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Bonjour le fil, bonjour le forum,

Je me demande comment tu arrives à faire tourner ton code sans déclarer tes variables mais surtout sans définir certaines... J'imagines qu'elles sont définies ailleurs...
Code:
Sub Macro1()

'Dim i As ...
'Dim NI1hdr As Range
'Dim lastcel As Range
'Dim NI1() As ...
'Dim NI1tmp() As ...
'Dim j As ...
'Dim MaxNbPack As ...
'Dim cel As Range
'Dim isinarray As Boolean
'Dim pack() As ...
'Dim fistfindrow As Integer
'Dim c As Range
'Dim packhdr As Range
'Dim packtmp() As ...
'Dim nbNI1 As ...

'Set NI1hdr = ...
'Set lastcel = ...
'Set packhdr - ...

' we are at the start. we make a list of all NI1.
i = 1
Do While NI1hdr.Offset(i, 0).Value = vbNullString 'loop until we find a non-empty cell (should be quick)
    i = i + 1
    If i = lastcel.Row Then MsgBox "No non-empty cells in the NI1 column: exiting macro now.": Exit Sub
Loop
ReDim Preserve NI1(0 To 0)
ReDim Preserve NI1tmp(0 To 0)
i = 0
MaxNbPack = 0
For Each cel In Range("I" & NI1hdr.Row + 1, "I" & lastcel.Row)
    If cel Is Nothing Then Resume Next
    isinarray = False
    For k = LBound(NI1tmp) To UBound(NI1tmp)
        If NI1tmp(k) = cel.Value Then isinarray = True 'check if NI1 is in the tmp array which mirrors the real one
    Next k
    j = 0
    If (Not isinarray) And cel.Value <> "" Then 'copy the NI1 to the array in i-th position
        'fill the pack array, then later assign it to the NI1 array
        ReDim Preserve pack(0 To j)
        pack(0) = cel.Value
        j = j + 1
        ReDim Preserve pack(0 To j)
        pack(j) = packhdr.Offset(cel.Row - firstrow + 1, 0).Value 'put the first found value into the first box
        firstfindrow = cel.Row
        Set c = Range(NI1hdr.Offset(1, 0), NI1hdr.Offset(lastcel.Row, 0))
        Set cel = c.Find(cel.Value, LookIn:=xlFormulas, _
           LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
        Do
            If cel Is Nothing Then Exit Do
            isinarray = False
            For k = 1 To j
                If packhdr.Offset(cel.Row - firstrow + 1, 0).Value = pack(k) Then isinarray = True 'check if packhdr.value is in NI1(i, j)
            Next k
            If Not isinarray Then
                j = j + 1
                ReDim Preserve pack(0 To j)
                pack(j) = packhdr.Offset(cel.Row - firstrow + 1, 0).Value
            End If
            Set cel = c.FindNext(cel) 'find next row with the current NI1
        Loop While cel.Row <> firstfindrow
        If j > MaxNbPack Then MaxNbPack = j
        ReDim Preserve packtmp(0 To i)
        packtmp(i) = j
        ReDim Preserve NI1(0 To i)
        NI1(i) = pack
        ReDim Preserve NI1tmp(0 To i)
        NI1tmp(i) = NI1(i)(0)
        i = i + 1
    End If
Next cel
nbNI1 = i - 1
End Sub

Et bien sûr le After:= qui posait problème...
 
Re : Erreur d'exécution '13' : Incompatibilité de type

Merci beaucoup Rober pour ta réponse. En fait les variables sont définies et déclarées plus haut dans la macro, que je n'ai pas écrit entièrement sur le forum.

Cela a l'air de fonctionner je vous tiens au courant si la situation évolue.

Encore merci pour vos réponses.

Cordialement,

Jeremouse1
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
461
Réponses
3
Affichages
543
Réponses
12
Affichages
861
Réponses
17
Affichages
2 K
Retour