View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
JMay JMay is offline
external usenet poster
 
Posts: 422
Default Excel VBA - Calculating average problem

Patrick:

I've been practicing on the example you gave the OP, but right now I'm
getting
a R/T error 1004 when running:

Sub PutMultiPartFormula()
Worksheets("Sheet3").Range("A1").FormulaR1C1 =
"=Sheet1!Average(R1C2:R10C2)"
End Sub

Can you offer assistance as to why this might be happening?
TIA,
JMay



"Patrick Molloy" wrote in message
...

Sub PutFormula()
Range("B3:B25").FormulaR1C1 = "=Average(RC3:RC137)"
End Sub

Sub PutFormula2()
Worksheets("Sheet1").Range("B3:B25").FormulaR1C1 =
"=Sheet3!Average(RC3:RC137)"
End Sub


This procedure places the appropriate formula into each cell in the range
B3:B25
No loop required.
The first simply uses the active sheet.
The second places th eformula on a sheet that does not need to be the

active
sheet....and I also set the formula to point to a different sheet



--
Patrick Molloy
Microsoft Excel MVP
----------------------------------
"Lena5il " wrote in message
...
Hi all,

I need to calculate an average in VBA excel.
I know only this form of calculation:
Worksheets(2).Cells(3, 2).Value = "=Average(Sheet1!C3:C137)"

But I need to calculate this for few columns and rows, hence I want to
use a loop. But I don't know how to write this formula with a variable
inside.

Help me, please,

Lena


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