tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
I have some data on my worksheet a follows:
I want something to sum the values according to the value in column a, ie I want a to return 3 and b to return 7.
The code above errors because it exceeds the dimension declared by Ubound.
So must I create a new array with one extra row, then read all the elements from MyArray into this new array before proceeding with the above code?
Like this:
Thanks
Code:
a 1
a 2
b 3
b 4
I want something to sum the values according to the value in column a, ie I want a to return 3 and b to return 7.
Code:
Dim MyArray() As Variant
MyArray = Cells(1, 1).CurrentRegion.Value
Dim Counter As Integer
For Counter = 1 To UBound(MyArray, 1)
If MyArray(Counter, 1) = MyArray(Counter + 1, 1) Then
End If
Next Counter
The code above errors because it exceeds the dimension declared by Ubound.
So must I create a new array with one extra row, then read all the elements from MyArray into this new array before proceeding with the above code?
Like this:
Code:
Dim MyArray() As Variant
MyArray = Cells(1, 1).CurrentRegion.Value
Dim NewArray() As Variant
ReDim NewArray(1 To UBound(MyArray, 1) + 1, 1) As Variant
Dim i As Integer
For i = 1 To UBound(MyArray, 1)
NewArray(i, 1) = MyArray(i, 1)
Next i
Dim Counter As Integer
For Counter = 1 To UBound(NewArray, 1) - 1
If NewArray(Counter, 1) = NewArray(Counter + 1, 1) Then
End If
Next Counter
Thanks
Last edited: