Мне была предоставлена функция VBA, которая работает, но я не понимаю, как она работает, и будет благодарна вам за помощь, потому что, как она была написана, исчисление действительно длинное (базовая арифметика * 15 000 строк)VBA Excel - переменная «Double» as function
Моя проблема исходит из определения двойной переменной Qty_Level, которая определяется следующим образом:
Dim Qty_Level(30) As Double
Я никогда не видел переменный, определенные как это, с парой круглых скобок как у функция. Вот мой код:
Sub cumul()
Dim i As Long
Dim j As Integer
Dim Qty_level(30) As Double
Dim Col_Niveau As Integer
Dim Col_Quantite As Integer
Dim Col_Resultat As Integer
i = InputBox("Veuillez indiquer le numéro de la première à analyser (numéro de ligne Excel)", "Ligne de départ")
Col_Niveau = InputBox("Veuillez indiquer le numéro de la colonne contenant les niveaux", "Niveaux")
Col_Quantite = InputBox("Veuillez indiquer le numéro de la colonne contenant les quantités", "Quantités")
Col_Resultat = InputBox("Veuillez indiquer le numéro de la colonne contenant les résultats", "Résultats")
Do While IsEmpty(Cells(i, Col_Niveau)) = False
If IsNumeric(Cells(i, Col_Quantite)) = True Then
Qty_level(Cells(i, Col_Niveau).Value) = Cells(i, Col_Quantite).Value
Cells(i, Col_Resultat).Value = 1
For j = 1 To Cells(i, Col_Niveau).Value
Cells(i, Col_Resultat).Value = Cells(i, Col_Resultat).Value * Qty_level(j)
Next j
End If
i = i + 1
Loop
End Sub
Я не понимаю, как это работает, и, в частности, как петля For
работает с Double(j)
'Dim Qty_level (30) Как Double' объявляет Qty_level как массив из 30 элементов Double. –
@PatriciaShanahan на самом деле как массив из 31 элемента :) – varocarbas
yep 31 добро пожаловать в VBA –