Erreur 13 uniquement lors du lancement mais pas avec le débogueur
Bonjour,
J'ai besoin d'aide je n'arrive pas a trouver l'origine de cette erreur, un regard extérieur pourrait m'aider.
Ce que je ne comprends surtout pas c'est pourquoi avec le débogueur j'arrive a exécuter le code mais pas en lançant ce dernier.
Le fichier est trop lourd, je vous mets juste le code.
La partie où apparait l'erreur est entre [----] (c'est la création du dernier graphique).
Dim TblGlobal()
Dim TblMac()
Private Sub BtnValidCol_Click()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim ws4 As Worksheet
Set ws = ThisWorkbook.Sheets(1)
Set ws2 = ThisWorkbook.Sheets(2)
Set ws3 = ThisWorkbook.Sheets(3)
Set ws4 = ThisWorkbook.Sheets(4)
Dim LastRow3 As Long
LastRow3 = ws3.Cells(ws3.Rows.Count, "A").End(xlUp).Row
Dim LastRow4 As Long
LastRow4 = ws4.Cells(ws4.Rows.Count, "A").End(xlUp).Row
i = 0
j = 0
For i = 2 To LastRow4
ReDim Preserve TblMac(1 To 6, 1 To i - 1)
'Numero de l'équipement
NomCol = ws.Cells(7, 5)
TblMac(1, i - 1) = ws4.Cells(i, NomCol)
'Nom de l'équipement
NomCol = ws.Cells(8, 5)
TblMac(2, i - 1) = ws4.Cells(i, NomCol)
'Ligne de production
NomCol = ws.Cells(9, 5)
TblMac(3, i - 1) = ws4.Cells(i, NomCol)
Next i
For i = 2 To LastRow3
NomCol = ws.Cells(13, 2)
NomCol2 = ws.Cells(10, 2)
If IsEmpty(ws3.Cells(i, NomCol)) = True Or Right(ws3.Cells(i, NomCol2), 2) = "PM" Then
Else
j = j + 1
ReDim Preserve TblGlobal(1 To 11, 1 To j)
'Numero de l'équipement
NomCol = ws.Cells(7, 2)
TblGlobal(1, j) = ws3.Cells(i, NomCol)
'Nom de l'équipement
NomCol = ws.Cells(8, 2)
TblGlobal(2, j) = ws3.Cells(i, NomCol)
'Description du probleme
NomCol = ws.Cells(10, 2)
TblGlobal(4, j) = ws3.Cells(i, NomCol)
'Description du travail fait
NomCol = ws.Cells(11, 2)
TblGlobal(5, j) = ws3.Cells(i, NomCol)
'Remarques
NomCol = ws.Cells(14, 2)
TblGlobal(6, j) = ws3.Cells(i, NomCol)
'Date d'enregistrement
NomCol = ws.Cells(9, 2)
TblGlobal(7, j) = ws3.Cells(i, NomCol)
'Date de début
NomCol = ws.Cells(12, 2)
TblGlobal(8, j) = ws3.Cells(i, NomCol)
'Date de fin
NomCol = ws.Cells(13, 2)
TblGlobal(9, j) = ws3.Cells(i, NomCol)
'Temps d'attente (h)
TblGlobal(10, j) = DateDiff("s", TblGlobal(7, j), TblGlobal(8, j))
TempoConvert = Abs(TblGlobal(10, j))
Call Convert_Date(TempoConvert)
TblGlobal(10, j) = TempoConvert
'Temps d'intervention (h)
TblGlobal(11, j) = DateDiff("s", TblGlobal(8, j), TblGlobal(9, j))
TempoConvert = Abs(TblGlobal(11, j))
Call Convert_Date(TempoConvert)
TblGlobal(11, j) = TempoConvert
'Ligne de production
For k = 1 To UBound(TblMac, 2)
If TblMac(1, k) = TblGlobal(1, j) Then
TblGlobal(3, j) = TblMac(3, k)
'Cumul des pannes
TblMac(4, k) = TblMac(4, k) + 1
'Cumul des temps d'attentes (s)
TblMac(5, k) = TblMac(5, k) + TblGlobal(10, j)
'Cumul des temps d'interventions (s)
TblMac(6, k) = TblMac(6, k) + TblGlobal(11, j)
Exit For
End If
Next k
End If
Next i
'__________________________________________________________________________________________________
'Creation des graphiques + Effacement des anciens
'__________________________________________________________________________________________________
For Each Graph In ws.ChartObjects
Graph.Delete
Next
'Creation du graphiqe : Cumul panne par équipement
Dim TblNMac()
Dim TblNbrPanne()
ReDim TblNMac(1 To UBound(TblMac, 2))
ReDim TblNbrPanne(1 To UBound(TblMac, 2))
For i = 1 To UBound(TblMac, 2)
TblNMac(i) = TblMac(1, i)
TblNbrPanne(i) = TblMac(4, i)
Next i
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Vue d'ensemble"
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = TblNMac()
.SeriesCollection(1).Values = TblNbrPanne()
.ChartType = xlLineMarkers
.ChartArea.Top = 600
.ChartArea.Left = 20
.ChartArea.Width = 4000
.ChartArea.Height = 600
End With
'Creation du graphique cumul des temps d'attentes et d'interventions par equipements
Dim TblCumulTA()
Dim TblCumulTI()
ReDim TblCumulTA(1 To UBound(TblMac, 2))
ReDim TblCumulTI(1 To UBound(TblMac, 2))
For i = 1 To UBound(TblMac, 2)
TblCumulTA(i) = TblMac(5, i)
TblCumulTI(i) = TblMac(6, i)
Next i
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Vue d'ensemble"
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = TblNMac()
.SeriesCollection(1).Values = TblCumulTA()
.SeriesCollection(1).Name = "Temps d'attente cumulé"
.SeriesCollection.NewSeries
.SeriesCollection(2).XValues = TblNMac()
.SeriesCollection(2).Values = TblCumulTI()
.SeriesCollection(2).Name = "Temps d'intervention cumulé"
.ChartType = xlLineMarkers
.ChartArea.Top = 1300
.ChartArea.Left = 20
.ChartArea.Width = 4000
.ChartArea.Height = 600
.Axes(xlValue).MaximumScale = 50000
End With
'Création du graphique nombre de pannes sur le temps
Dim TblDateUnik() 'Attention Base 0
Dim TblPanneDate()
Dim Dico As Object
Set Dico = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(TblGlobal, 2)
If Left(TblGlobal(7, i), 10) <> "" Then Dico(CDate(Left(TblGlobal(7, i), 10))) = ""
Next i
TblDateUnik = Dico.Keys
Call Tri(TblDateUnik, 0, UBound(TblDateUnik))
ReDim TblPanneDate(0 To UBound(TblDateUnik))
For i = 0 To UBound(TblDateUnik, 1)
For j = 1 To UBound(TblGlobal, 2)
If TblDateUnik(i) = CDate(Left(TblGlobal(7, j), 10)) Then
TblPanneDate(i) = TblPanneDate(i) + 1
End If
Next j
Next i
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Vue d'ensemble"
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = TblDateUnik()
.SeriesCollection(1).Values = TblPanneDate()
.ChartType = xlColumnClustered
.ChartArea.Top = 2000
.ChartArea.Left = 20
.ChartArea.Width = 4000
.ChartArea.Height = 600
.HasLegend = False
End With
'Mise en forme du graphique, differenciation de la semaine (vert) et du weekend (rouge)
Dim P As Point
Dim ValeurP As Date
i = 0
For Each P In ActiveChart.SeriesCollection(1).Points
i = i + 1
ValeurP = TblDateUnik(i - 1)
If Weekday(ValeurP) = 1 Then
ActiveChart.SeriesCollection(1).Points(i).Interior.ColorIndex = 30
ElseIf Weekday(ValeurP) = 2 Then
ActiveChart.SeriesCollection(1).Points(i).Interior.ColorIndex = 50
ElseIf Weekday(ValeurP) = 3 Then
ActiveChart.SeriesCollection(1).Points(i).Interior.ColorIndex = 50
ElseIf Weekday(ValeurP) = 4 Then
ActiveChart.SeriesCollection(1).Points(i).Interior.ColorIndex = 50
ElseIf Weekday(ValeurP) = 5 Then
ActiveChart.SeriesCollection(1).Points(i).Interior.ColorIndex = 50
ElseIf Weekday(ValeurP) = 6 Then
ActiveChart.SeriesCollection(1).Points(i).Interior.ColorIndex = 50
ElseIf Weekday(ValeurP) = 7 Then
ActiveChart.SeriesCollection(1).Points(i).Interior.ColorIndex = 30
End If
Next P
'Creation du graphique nombre de panne par ligne de production
Dim TblLigne()
Dim TblPanneLigne()
Dim Dico2 As Object
Set Dico2 = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(TblMac, 2)
If TblMac(3, i) <> "" Then Dico2(TblMac(3, i)) = ""
Next i
TblLigne = Dico2.Keys
ReDim TblPanneLigne(0 To UBound(TblLigne, 1))
For i = 0 To UBound(TblLigne, 1)
For j = 1 To UBound(TblGlobal, 2)
If TblLigne(i) = TblGlobal(3, j) Then
TblPanneLigne(i) = TblPanneLigne(i) + 1
End If
Next j
Next i
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Vue d'ensemble"
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = TblLigne()
.SeriesCollection(1).Values = TblPanneLigne()
.ChartType = xlColumnClustered
.ChartArea.Top = 50
.ChartArea.Left = 600
.ChartArea.Width = 700
.ChartArea.Height = 500
.HasLegend = False
End With
'Creation du graphique temps d'attente et d'intervention par ligne de production
Dim TblTALigne()
Dim TblTILigne()
ReDim TblTALigne(0 To UBound(TblLigne, 1))
ReDim TblTILigne(0 To UBound(TblLigne, 1))
For i = 0 To UBound(TblLigne, 1)
For j = 1 To UBound(TblGlobal, 2)
If TblLigne(i) = TblGlobal(3, j) Then
TblTALigne(i) = TblTALigne(i) + TblGlobal(10, j)
TblTILigne(i) = TblTILigne(i) + TblGlobal(11, j)
End If
Next j
Next i
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Vue d'ensemble"
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = TblLigne()
.SeriesCollection(1).Values = TblTALigne()
.SeriesCollection(1).Name = "Temps d'attente cumulé"
.SeriesCollection.NewSeries
.SeriesCollection(2).XValues = TblLigne()
.SeriesCollection(2).Values = TblTILigne()
.SeriesCollection(2).Name = "Temps d'intervention cumulé"
.ChartType = xlLineMarkers
.ChartArea.Top = 50
.ChartArea.Left = 1400
.ChartArea.Width = 700
.ChartArea.Height = 500
.Axes(xlValue).MaximumScale = 300000
End With
'Creation du graphique nombre de panne par poste
Dim TblPoste(1 To 5)
Dim TblPannePoste(1 To 5)
Dim Sem As Boolean
Dim DateP As Date
Dim HeureP As Date
Sem = True
TblPoste(1) = "Sem 5h - 13h"
TblPoste(2) = "Sem 13h - 21h"
TblPoste(3) = "Sem 21h - 5h"
TblPoste(4) = "WE 5h - 17h"
TblPoste(5) = "WE 17h - 5h"
[--------------------------------------------------------------------------------------------------------------------------------]
For m = 1 To UBound(TblGlobal, 2)
DateP = CDate(Left(TblGlobal(7, m), 10))
HeureP = CDate(Right(TblGlobal(7, m), 8))
If Weekday(DateP) = 1 Then
Sem = False
ElseIf Weekday(DateP) = 7 Then
Sem = False
Else
Sem = True
End If
If Sem = False And HeureP > #5:00:00 AM# And HeureP < #5:00:00 PM# Then
TblPannePoste(4) = TblPannePoste(4) + 1
ElseIf Sem = False And (#12:00:00 AM# < HeureP < #5:00:00 AM# Or #5:00:00 PM# < HeureP < #12:00:00 AM#) Then
TblPannePoste(5) = TblPannePoste(5) + 1
ElseIf Sem = True And HeureP > #5:00:00 AM# And HeureP < #1:00:00 PM# Then
TblPannePoste(1) = TblPannePoste(1) + 1
ElseIf Sem = True And HeureP > #1:00:00 PM# And HeureP < #9:00:00 PM# Then
TblPannePoste(2) = TblPannePoste(2) + 1
ElseIf Sem = True And (#9:00:00 PM# < HeureP < #12:00:00 AM# Or #12:00:00 AM# < HeureP < #5:00:00 AM#) Then
TblPannePoste(3) = TblPannePoste(3) + 1
End If
On Error GoTo Line1
Line1:
MsgBox (m & "est le numero de la ligne")
Exit Sub
[--------------------------------------------------------------------------------------------------------------------------------]
Next m
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Vue d'ensemble"
With ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = TblPoste()
.SeriesCollection(1).Values = TblPannePoste()
.ChartType = xlColumnClustered
.ChartArea.Top = 50
.ChartArea.Left = 2200
.ChartArea.Width = 700
.ChartArea.Height = 500
.HasLegend = False
End With
' Suppression des tableaux pour ne pas cumulé les informations
Erase TblGlobal
Erase TblMac
End Sub
Sub Convert_Date(x As Variant)
Dim Heure As Double
Dim Minute As Double
Dim Seconde As Double
Heure = WorksheetFunction.RoundDown(x / 3600, 0)
x = x - (Heure * 3600)
Minute = WorksheetFunction.RoundDown(x / 60, 0)
MinuteD = Minute / 60
Seconde = (WorksheetFunction.RoundDown(x - (Minute * 60), 0)) / 3600
x = Heure + MinuteD + Seconde
End Sub
Sub Tri(a, gauc, droi) ' Quick sort
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi)
If gauc < d Then Call Tri(a, gauc, d)
End SubMerci d'avance pour votre aide.
Bonjour,
En général quand ça se passe comme ça c'est parce que en mode débogage tu actives la ws qui va bien et qui n'est pas précisée dans le code.
Je suppose qu'il s'agit de tous tes graph et ActiveGraph... Je leurs collerai bien du ws... pour voir !
Après au lieu des ActiveChart j'essaierai bien du :
Dim NewC as Chart
Set NewC = ws.Chart.Add
With NewC...
A+
Bonjour,
Je viens d'essayer et le ws.Chart.Add ne passe pas du tout, j'ai essayer avec ChartObjects mais j'ai une erreur 450