bishop3000
asked on
VBA: Getting Range Averages w/o #DIV/0!
Hi,
In the VBE, I'm looping through a spreadsheet (that I can't modify) to get averages. Some ranges I'm getting averages for consist of all blank cells--so the result in those cases shows "#DIV/0!". What's the best way to make VBE give those ranges a "0" value, rather than a "#DIV/0!" value?
Here's the code format:
Sub RangeAvg()
Dim i as Integer, ShadeAvg as Integer, JanArray
For i = 3 To 57 Step 2
ShadeAvg = Application.Average(Range( Cells(16, i), Cells(46, i + 1)))
JanArray((i - 1) / 2) = ShadeAvg
Next i
Range("d4:ae4").Value = JanArray()
End Sub
Thanks!
-Michael
In the VBE, I'm looping through a spreadsheet (that I can't modify) to get averages. Some ranges I'm getting averages for consist of all blank cells--so the result in those cases shows "#DIV/0!". What's the best way to make VBE give those ranges a "0" value, rather than a "#DIV/0!" value?
Here's the code format:
Sub RangeAvg()
Dim i as Integer, ShadeAvg as Integer, JanArray
For i = 3 To 57 Step 2
ShadeAvg = Application.Average(Range(
JanArray((i - 1) / 2) = ShadeAvg
Next i
Range("d4:ae4").Value = JanArray()
End Sub
Thanks!
-Michael
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Kevin,
You are the man.
Thank you!
-Michael
You are the man.
Thank you!
-Michael
Sub RangeAvg()
Dim i as Integer, ShadeAvg as Integer
Dim JanArray(1 To 28) As Double
For i = 3 To 57 Step 2
ShadeAvg = Application.Average(Range(
JanArray((i - 1) \ 2) = ShadeAvg
Next i
Range("d4:ae4").Value = JanArray
End Sub
Kevin