[debutant] Run-time error '9': Subscript out of range
Bonjour,
J'ai le problème suivant lors de l'execution de ma fontion:
Run-time error '9': Subscript out of range
et voici le code fautif (dernière ligne):
Code:
1 2 3 4 5 6 7 8 9
|
Dim Tab_tranche() 'No "As" as has to be of "Variant" type
Dim Tab_taux() 'No "As" as has to be of "Variant" type
Tab_tranche = Sheets("Data").Range("B4:B10").Value
Tab_taux = Sheets("Data").Range("C4:C10").Value
MsgBox LBound(Tab_tranche)
MsgBox UBound(Tab_tranche)
MsgBox Tab_tranche(1) |
Effectivement, je ne déclare jamais le nombre exact d'éléments de mon tableau, mais les deux premières messages box me donnent bien respectivement "1" et "7", ce qui me semble correct.
Si je redimensionne le tableau après lui avoir affecté des valeurs, j'obtiens alors
Code:
1 2 3 4 5 6 7 8 9 10
|
Dim Tab_tranche() 'No "As" as has to be of "Variant" type
Dim Tab_taux() 'No "As" as has to be of "Variant" type
Tab_tranche = Sheets("Data").Range("B4:B10").Value
Tab_taux = Sheets("Data").Range("C4:C10").Value
ReDim Tab_tranche(UBound(Tab_tranche))
MsgBox LBound(Tab_tranche)
MsgBox UBound(Tab_tranche)
MsgBox Tab_tranche(1) |
J'obtiens alors "0" comme lower bound (et toujours "7" comme upper).
Par contre, plus de bug lors de l'exécution de la dernière ligne, mais la valeur renvoyée est vide (hors la cellule en question est bien remplie)
Je suis débutant en VBA et ne comprend pas encore bien tous les impacts.
Quelqu'un pourrait m'éclairer svp ?
Merci d'avance