View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Matthew Dyer Matthew Dyer is offline
external usenet poster
 
Posts: 178
Default 2 dimensional loop, averageif formula

On Mar 23, 5:54*pm, joeu2004 wrote:
On Mar 23, 4:27*pm, Matthew Dyer wrote:

i'm struggling with the averageif formula. help?

[....]
For i = LastRw + 2 To LastRw + 4
* * For ii = LastCol - 37 To LastCol
* * Cells(i, ii).Formula = "=averageif(a1:a" & lastrw & ",b" &i&
",c1:c" &lastcol& ")"
* * Next ii
Next i


I find it helpful to write a prototype of the formula in Excel and
perhaps even test it in Excel first.

Also, when you ask a syntax question, it is essential that you copy-
and-paste from Excel or VBA into your posting. *Apparently you did
not, since VBA does like &i& [sic]; that is, ampersand without
surrounding whitespace.

Or that the problem you want to solve? *You never tell us what it is.

It also seems odd to me that the only thing that will change in your
AVERAGEIF is i. *My guess is that you also want to "b" to vary with
ii.

Is that another part of the probem you want to solve? *Again, you
never really explain what you want AVERAGEIF to look like in each
going across as well as down.


Sorry about the confusion in my description... The syntax of the loop
is correct. It is the averageif formula i'm having difficulty with.
for the first instance of the formula being placed the very first cell
of the loop, here is what I want it to read:
=averageif(a1:a15, b17, c1:c15)

if I were to use auto-fill to drag the formula to every cell i wanted
it in, it would look like this:
=averageif($a$1:$a:$15, $b17, c$1:c$15)
but, since i want to automate it, i'm trying to figure out how to use
the loop variables to fill in the formula as it goes from cell to
cell. does this help?