Для платформы программирования с 32-битным артикулом: «Dim Item1 As Long», переменная имеет длину 32-бит. Это означает, что каждая переменная с длинным затемнением является 32-битной. Максимальное значение, которое оно может содержать (положительное или отрицательное), составляет немногим более 2 млрд.
Sub sumall()
Dim firstRow As long
firstRow = 5
Dim lastRow Aslong
lastRow = 12
Dim aRow As long
Dim sumall As Variant
Dim sumResult As Variant
sumResult = 0
Dim previousValue As Variant
previousValue = -1
For aRow = firstRow To lastRow
If Cells(aRow, 2).Value <> previousValue Then
sumResult = Cells(aRow, 2).Value
previousValue = Cells(aRow, 2)
End If
Next aRow
sumall = sumResult
End Sub
Другой вариант для tasc - использовать scriptingDictionary для получения только уникальных значений:
Sub sumall()
Dim objDictionary As Object
Dim firstRow As Long
firstRow = 5
Dim lastRow As Long
lastRow = 12
Dim aRow As Variant
Dim varKey As Variant
Dim sumResult As Variant
Set objDictionary = CreateObject("Scripting.Dictionary")
For aRow = firstRow To lastRow
If objDictionary.exists(Cells(aRow, 2).Value) = False Then
objDictionary.Add Cells(aRow, 2).Value, True
End If
Next aRow
sumResult = 0
For Each varKey In objDictionary.keys
sumResult = varKey + sumResult
Next varKey
End Sub