max = 10 ' max holds the number of fields you want to process
total = 0 ' a running rally valid values summed together
count = 0 ' a running tally of the number of valid values
upperLimit = 100 ' the upper limit of a valid value
upperLimit = 50 ' the lower limit of a valid value
' Loop through a column of data that you want selectively averaged
for i = 0 to max
' See if a variable falls within the preset boundaries
if (range("firstCell").offset(i, 0).value > lowerLimit and range("firstCell").offset(i, 0).value < upperLimit) then
total = total + range("firstCell").offset(i, 0).value
count = count + 1
end if
next i
' Process the average
average = total / count
msgbox("Average of valid values is " & average)