Runtime Error 13 Type Mismatch
Solved
grace
-
pijaku Posted messages 13513 Registration date Status Modérateur Last intervention -
pijaku Posted messages 13513 Registration date Status Modérateur Last intervention -
Hello,
I don't understand why I have a runtime error 13: type mismatch because my code was working fine before... I have highlighted the line where the error occurs in bold
What's strange is that it runs the code correctly since all relevant rows are copied and pasted into the recap! There must be a bug at the end of the loop...(I think!)
Thank you in advance if you can help me...my PC is going to end up through the window!!!!
Configuration: Windows 2003 / Internet Explorer 7.0
I don't understand why I have a runtime error 13: type mismatch because my code was working fine before... I have highlighted the line where the error occurs in bold
'displaying the relevant sheets and checking the fields Sheets("Recap").Visible = True If Categories = "" Then MsgBox "Select a category of defects from the dropdown list" ElseIf defects = "" Then MsgBox "Select a quality defect from the dropdown list" Exit Sub End If Dim i As Integer Dim n As Integer n = 3 i = 2 MsgBox "Please wait while processing..." Application.Cursor = xlWait 'displays the hourglass 'Deleting data from the recap Worksheets("Recap").Range("A3:Z1500").ClearContents 'search for the rows where there is a defect and the selected machine(s) 'copy the rows and paste them into the recap If defects <> "" Then n = 3 i = 2 Do While Cells(i, 1) <> "" <bold>If Cells(i, 3) = defects 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 'Sort the data by 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 'reset the cursor to default Else Exit Sub End If End Sub What's strange is that it runs the code correctly since all relevant rows are copied and pasted into the recap! There must be a bug at the end of the loop...(I think!)
Thank you in advance if you can help me...my PC is going to end up through the window!!!!
Configuration: Windows 2003 / Internet Explorer 7.0
2 answers
Hello,
In general, runtime error 13: type mismatch is due to a bad variable declaration or improper use of that variable.
Example:
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
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
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
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 SubThis 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