Average of Changing Range Problem

ianfrancis56

New Member
Joined
Aug 10, 2011
Messages
34
Hi all,

I'm a little fried and I cannot figure out why this won't work, although I have a suspicion it has to do with the Range the Average function is being applied to.

Code:
Sub Returns()

Dim z@, y@, x@

With Sheets(1)
For z = 2 To 3
    For x = 2 To y = .Cells(2, z).End(xlDown).Row
        .Cells(x, z + 2) = .Application.Average( _
        .Range(.Cells(x, z).End(xlDown).Row))
    Next x
    Next z
End With

End Sub

Is Sheet 1 Columns B and C (starting in Row 2) are values. I want to look at the Average value of each column as it moves down (ie Average of values in cells B2 to the end, then with B3 being the first cell in the calculation, etc...). Appreciate any help, thanks!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try:


Code:
Sub Returns()

Dim z@, y@, x@

With Sheets(1)
y = .Cells(2, 2).End(xlDown).Row
Range("D2").Select
For z = 2 To 3
    For x = 2 To y
        .Cells(x, z + 2).FormulaR1C1 = "=Average(R2C[-2]:RC[-2])"
    Next x
ActiveCell.Offset(, 1).Select
Next z
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,823
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top