Erreur d'exécution 13 Incompatibilité de type

Solved
grace -  
pijaku Posted messages 13513 Registration date   Status Modérateur Last intervention   -
Bonjour,

Je ne comprend pas pourquoi j'ai une erreur d'execution 13 : incompatibilité de type car mon code marchait très bien avant...Je met en gras la ligne où il y a l'erreur

'affichage des feuilles concernées et vérification des champs
Sheets("Recap").Visible = True
If Cathégories = "" Then
MsgBox "Sélectionnez une catégorie de défauts dans la liste déroulante"
ElseIf défauts = "" Then
MsgBox "Sélectionnez un défauts qualité dans la liste déroulante"
Exit Sub
End If

Dim i As Integer
Dim n As Integer
n = 3
i = 2

MsgBox "Veuillez patienter pendant le traitement..."
Application.Cursor = xlWait   'affiche le sablier

'Suppression des données du récap
Worksheets("Recap").Range("A3:Z1500").ClearContents

'recherche les lignes ou il y a le défaut et la/les machine/s choisie
'copie les lignes et les colle dans la récap
If défauts <> "" Then
n = 3
i = 2
Do While Cells(i, 1) <> ""

<bold>If Cells(i, 3) = défauts Then</bold>
j = 1
Do While Sheets("Machines").Cells(j, 1) <> ""
If Cells(i, 1) = Sheets("Machines").Cells(j, 1) Then
Worksheets("2011 (2)").Select
Worksheets("2011 (2)").Rows(i).Select
Worksheets("2011 (2)").Rows(i).Copy
Worksheets("Recap").Select
Worksheets("Recap").Rows(n).Select
ActiveSheet.Paste
n = n + 1
Worksheets("2011 (2)").Select
End If
j = j + 1
Loop

End If
i = i + 1
Loop

Sheets("Machines").Visible = False

'Trier les données par machine
Worksheets("Recap").Select
Range("A2:Z1500").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End If
Application.Cursor = xlDefault 'remet le curseur par défaut
Else
Exit Sub
End If
End Sub


Ce qui est bizarre c'est qu'il fait le code correctement puisque toutes lignes concernées sont copiées et collées dans la récap! Il doit y avoir un bug sur la fin de la boucle...(je pense!)
Merci d'avance si vous pouvez m'aider...mon PC va finir par la fenetre!!!!
Configuration: Windows 2003 / Internet Explorer 7.0

2 answers

pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 770
 
Hello,
In general, runtime error 13: type mismatch is due to a bad variable declaration or improper use of that variable.
Example:
Dim MyVar As String MyVar = "Text" MsgBox CDbl(MyVar)
will throw the aforementioned runtime error 13.

The code you provided above is incomplete.
- Could you please give it to us in its entirety, from Sub Machin() to End Sub?
- Where is it placed? Standard module, sheet module...
- Have you enabled Option Explicit (mandatory variable declaration)?
--
Best regards,
Franck P
7
grace
 
Hello,

Thank you for your comment...
Actually, I ended up finding it myself. It turns out that my cells were in standard format while I was treating them as text in my program. So I converted everything to text cell format... and no more errors!

Thank you anyway for providing me with a response.
Grace
2
achacheachache Posted messages 14 Registration date   Status Member Last intervention   1
 
Hello, I have the same error with this program, I've been trying to debug it for 3 days and I still can't.
Can you help me please


Public Sub Essai() Dim i As Integer, DerniereLigne As Integer With Worksheets("Situation 092014 à 012015") DerniereLigne = .Range("A65536").End(xlUp).Row For i = DerniereLigne To 1 Step -1 If .Cells(i, 2) = "" And _ .Cells(i, 3) = "" And _ .Cells(i, 4) = "" And _ .Cells(i, 5) = "" And _ .Cells(i, 6) = "" And _ .Cells(i, 1) <> "Absence" And _ .Cells(i, 1) <> "activité syndicale hors poste de travail" And _ .Cells(i, 1) <> "Délégation" And _ .Cells(i, 1) <> "Delegation HC" And _ .Cells(i, 1) <> "autres absences " And _ .Cells(i, 1) <> "autres activités" And _ .Cells(i, 1) <> "Présence activité syndicale" And _ .Cells(i, 1) <> "" And _ .Cells(i, 1) <> "sous total" Then .Rows(i).Delete End If 'If a row in the workbook has no values in these columns, it will be deleted.. 'Absence, presence in union activities, other activities, other absences, subtotals, and totals will not be deleted Next i End With End Sub
0
pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 770 > achacheachache Posted messages 14 Registration date   Status Member Last intervention  
 
Hello,

This message is a duplicate.
So I will reply to you in the original discussion.
The continuation here: https://forums.commentcamarche.net/forum/affich-31586037-help-erreur-13-incompatibilite-type
0