View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Max of VBA Array

Sub Tester1()
Dim UnitOfferArray(1 To 13, 1 To 9) As Double
Dim var As Double
UnitOfferArray(1, 9) = 49.2126
UnitOfferArray(2, 9) = 39.7223
UnitOfferArray(3, 9) = 28.0002
UnitOfferArray(4, 9) = 27.943
UnitOfferArray(5, 9) = 11.2936
UnitOfferArray(6, 9) = 7.6502
UnitOfferArray(7, 9) = 4.6001
UnitOfferArray(8, 9) = 1.7726
UnitOfferArray(9, 9) = 1.2268
UnitOfferArray(10, 9) = 1.1163
UnitOfferArray(11, 9) = 0
UnitOfferArray(12, 9) = 0
UnitOfferArray(13, 9) = 0
var = Application.Sum(Application.Index(UnitOfferArray, 0, 9))
Debug.Print var

End Sub

produced:
172.5377

if you declare the lower bound, then there is no doubt what it is.
--
Regards,
Tom Ogilvy

"ExcelMonkey " wrote in message
...
I have a two dimensional array. I have tried to sum the second column of
it. When I test I get a sum of 0 but when I test the individual values
I clearly get numbers that are greater than 0 and should then Max to
the highest of those numbers. What I am I doing wrong?

Public UnitOfferArray() As Variant
Dim ArrayMax As Variant

ArrayMax = Application.Max(Application.Index(UnitOfferArray, 0, 9))

?ArrayMax
0

?UnitOfferArray(1, 9)
49.2126
?UnitOfferArray(2, 9)
39.7223
?UnitOfferArray(3, 9)
28.0002
?UnitOfferArray(4, 9)
27.943
?UnitOfferArray(5, 9)
11.2936
?UnitOfferArray(6, 9)
7.6502
?UnitOfferArray(7, 9)
4.6001
?UnitOfferArray(8, 9)
1.7726
?UnitOfferArray(9, 9)
1.2268
?UnitOfferArray(10, 9)
1.1163
?UnitOfferArray(11, 9)
0
?UnitOfferArray(12, 9)
0
?UnitOfferArray(13, 9)
0


---
Message posted from http://www.ExcelForum.com/