Erreur d'execution '6' Dépassement de capacité

Résolu
Bonjour, Je débute en VBA, voici mon code.
Mon problème est comme intitulé dans le titre que lorsque je lance mon programme le message d'erreur erreur d'execution 6 dépassement de capacité.

Mon tableau à comme dimension 40 colonnes / 365 000 lignes.

Sub Graphique_Compactage()
'
' Graphique_Compactage Macro
' Crée un graphique confrontant les forces de compactage demandée et apliquée en fonction du temps
'
' Touche de raccourci du clavier: Ctrl+Shift+C
'
Dim O As Worksheet
Dim R As Range
Dim COL As Integer
Dim LI As Integer

Set O = Worksheets("ProductionParameters")
Set R = O.Rows(1).Find("Force de compactage (Mesure) - 82", , xlValues, xlWhole)
If R Is Nothing Then Exit Sub
COL = R.Column
LI = O.Cells(Application.Rows.Count, "A").End(xlUp).Row
Set pl = Application.Union(O.Range(O.Cells(1, 1), O.Cells(LI, 1)), O.Range(O.Cells(1, COL), O.Cells(LI, COL)))
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=pl
O.Cells(1, COL).Select
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:= _
"Graphique Compactage"
ActiveChart.ClearToMatchStyle
ActiveChart.ChartStyle = 241
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
ActiveChart.Axes(xlValue).HasTitle = True
ActiveChart.Axes(xlCategory).AxisTitle.Select
Selection.Caption = "Temps en HH:MM:SS"
ActiveChart.Axes(xlValue).AxisTitle.Select
Selection.Caption = "Force en Newton"
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).Select
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "h:mm;@"
ActiveChart.ChartArea.Select
ActiveChart.ChartTitle.Select
Selection.Caption = "Forces de compactage demandée et apliquée en fonction du temps"
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "[$-x-systime]h:mm:ss AM/PM"
ActiveChart.ChartArea.Select
ActiveChart.SetElement (msoElementLegendTop)
End Sub



La ligne qui pose problème est :

LI = O.Cells(Application.Rows.Count, "A").End(xlUp).Row

comment contourné la limite de capacité ?

Merci d'avance pour votre aide.

1 réponse

  1. Contributeur
    bonjour

    tu as déclaré LI as integer pour identifier la dernière ligne utilisée
    le typte integer va de -32 768 et 32 767 ( 2 octets)...

    il faut donc que tu déclares LI as long : -2 147 483 648 et 2 147 483 647 (4 octets)

    Au passage :
    40colonnes---> à déclarer " as byte" (va de 0 a 255--> 1 octet) au lieu d'integer.

    Edit:
    Topos sur les variables
    https://silkyroad.developpez.com/VBA/LesVariables/
    https://mhubiche.developpez.com/Access/variables/

     Michel
    0
    1. Merci pour ta réponse michel
      0