Bonjour,
j'essaie de faire tourner le code très simple ci-dessous et je récupère une erreur 6 "dépassement de capacité" que je ne comprends pas. Quand je passe en debug, la console pointe vers l'instruction en rouge ci-dessous. Pas de problème si j'exécute pas à pas.
Merci.
Sub vba_loop_range()
Dim iCell As Range
Dim rowNum, colNum As Integer
Dim TopAccounts(9) As String
Dim Values(9) As Double
Dim Account As String
Dim Invoicing As Double
Dim Bottom10 As Double
Dim i As Integer
Bottom10 = 0
For Each iCell In Range("H:H").Cells
rowNum = iCell.Row
Account = iCell.Value
If Account = "Total général" Then
Exit For
End If
If rowNum > 1 Then
colNum = iCell.Column
Invoicing = Cells(rowNum, colNum + 1).Value
Debug.Print Account & " " & Invoicing & " " & Bottom10
If Invoicing > Bottom10 Then
Call insert_value(TopAccounts, Values, Account, Invoicing)
Bottom10 = Values(9)
Debug.Print "Bottom10 " & Bottom10
End If
End If
Next iCell
For i = 0 To 9
Worksheets("VBATests").Cells(i + 1, 1).Value = TopAccounts(i)
Worksheets("VBATests").Cells(i + 1, 2).Value = Values(i)
Next
End Sub
Sub push_values_down(TopAccounts() As String, Values() As Double, startRow As Integer)
Dim i As Integer
If startRow >= 0 And startRow < 9 Then
For i = 8 To startRow Step -1
TopAccounts(i + 1) = TopAccounts(i)
Values(i + 1) = Values(i)
Next
End If
End Sub
Sub insert_value(TopAccounts() As String, Values() As Double, Account As String, Invoicing As Double)
Dim i As Integer
Debug.Print "In insert_value " & Invoicing
For i = 0 To 9
If Invoicing > Values(i) Then
Debug.Print "In insert_value " & i & " " & Values(i)
Call push_values_down(TopAccounts(), Values(), i)
TopAccounts(i) = Account
Values(i) = Invoicing
Exit Sub
End If
Next
End Sub
Partager