En VBA, je peux facilement insérer une feuille dans un tableau, la manipuler, puis la renvoyer à la feuille \ range. J'ai du mal à le faire dans VB.Net cependant.Utilisation des plages et des tableaux Excel
Voici mon code.
Rng = .Range("a4", .Cells(.UsedRange.Rows.Count, .UsedRange.Columns.Count))
Dim SheetArray(,) As Object = DirectCast(Rng.Value(Excel.XlRangeValueDataType.xlRangeValueDefault), Object(,))
For X As Integer = 0 To SheetArray.GetUpperBound(0)
If IsNothing(SheetArray(X, 0)) Then Exit For
SheetArray(X, 6) = SheetArray(X, 3)
SheetArray(X, 7) = CDbl(SheetArray(X, 3).ToString) - CDbl(SheetArray(X, 1).ToString) - _
CDbl(SheetArray(X, 7).ToString)
For Y As Integer = 0 To 3
SheetArray(X, Y * 2 + 1) = Math.Round(CDbl(SheetArray(X, Y * 2 + 1).ToString), 3)
Next
If Math.Abs(CDbl(SheetArray(X, 7).ToString)) > 0.1 Then _
.Range(.Cells(X + 1, 1), .Cells(X + 1, 8)).Font.Color = -16776961
Next
Je reçois une erreur sur la première ligne If IsNothing(SheetArray(X, 0)) Then Exit For
. Il me dit que l'index est hors limites du tableau. Une idée pourquoi? L'objet SheetArray
contient les données, mais je ne suis pas sûr de savoir comment y accéder.