PDA

View Full Version : How to sum without using a worksheet function



reeza
11-02-2015, 09:24 AM
So I needed to create a random range and then calculate the average of that range. Once the average is calculated I need to:

A) Calculate how many numbers are greater than the average, highlight all numbers greater than the average and place the amount of numbers that are greater than the average in a cell.

B) Calculate the sum of the numbers that are greater than the average and place that in a cell. However I need to calculate the sum without using the worksheet function.The code below creates a random range, and works out an average. If there is a more efficient way to do so, please feel free to contribute.

I am Using Excel 2010


Sub Example1()
Dim RandRange As Range

Set ExampleRange = Range("C2:J12")
With ExampleRange
.Formula = "=Rand()"
.Font.Bold = True
End With


With Range("C14")
.Value = "Average"
.Offset(0, 1).Name = "Average"
.Offset(0, 1).Formula = "=average(RandRange)"
End With

Aflatoon
11-02-2015, 09:56 AM
However I need to calculate the sum without using the worksheet function.

And why might that be? Sounds a lot like an assignment to me...