occuring error in vba programme

H

harry

the programme i wrote is to return the maximum, minimum and average
of
100 numbers. But it keeps returning an error. Does anyone no whats
wrong with it? what its missing?
cheers

Sub testing()
Dim a(10) As Single, max As Single
Dim min As Single, sum As Single
Dim Average As Integer, i As Integer
n = 100
max = a(1)
min = a(1)
sum = a(1)
For i = 1 To 100
If max > a(i) Then max = a(i)
If min < a(i) Then
min = a(i)
End If
sum = sum + a(i)
Next i
Average = sum / n
End Sub
 
Z

zkid

From what I can see, you never loaded your array with data. Are you just
using 1 to 100, or are do you plan to load various numbers in from elsewhere?
Plus, you said you want to perform this on 100 numbers, yet your array only
has 10 placeholders (a(10)). In addition, if you are not using Option Base
1, the index to access the array goes from 0-9, not 1-10.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top