Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Formula.array in excel macros

Hi Guys I am trying to use this macro ..

Sub testingaverage()
Set rng = ActiveSheet.UsedRange
lastRow = rng.Rows(rng.Rows.Count).Row
For i = 1 To lastRow Step 100
Cells(i, "L").FormulaArray = "=Average(f1:f100)"
Next
End Sub


This macro gives me average for F1:F100 in every 100th row of column
L.

What I want to do is :
----the first time I get average it should be F1:F100
----second time It should be F101:F200
---Third time F201:F300 ....... and so on .....

So basically my question is how do I change the x value in Fx

Any help would be great

Thanks
Chinmay

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Formula.array in excel macros

First, =average() doesn't need to be array entered:

Option Explicit
Sub testingaverage()
Dim myRng As Range
Dim rng As Range
Dim LastRow As Long
Dim i As Long

With ActiveSheet
Set rng = .UsedRange
LastRow = rng.Rows(rng.Rows.Count).Row
For i = 1 To LastRow Step 100
Set myRng = .Cells(i, "F").Resize(100, 1)
.Cells(i, "L").Formula _
= "=Average(" & myRng.Address(external:=True) & ")"
Next i
End With
End Sub

Chinmaybl wrote:

Hi Guys I am trying to use this macro ..

Sub testingaverage()
Set rng = ActiveSheet.UsedRange
lastRow = rng.Rows(rng.Rows.Count).Row
For i = 1 To lastRow Step 100
Cells(i, "L").FormulaArray = "=Average(f1:f100)"
Next
End Sub

This macro gives me average for F1:F100 in every 100th row of column
L.

What I want to do is :
----the first time I get average it should be F1:F100
----second time It should be F101:F200
---Third time F201:F300 ....... and so on .....

So basically my question is how do I change the x value in Fx

Any help would be great

Thanks
Chinmay


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Formula.array in excel macros

On Mar 1, 11:24 pm, Dave Peterson wrote:
First, =average() doesn't need to be array entered:

Option Explicit
Sub testingaverage()
Dim myRng As Range
Dim rng As Range
Dim LastRow As Long
Dim i As Long

With ActiveSheet
Set rng = .UsedRange
LastRow = rng.Rows(rng.Rows.Count).Row
For i = 1 To LastRow Step 100
Set myRng = .Cells(i, "F").Resize(100, 1)
.Cells(i, "L").Formula _
= "=Average(" & myRng.Address(external:=True) & ")"
Next i
End With
End Sub



Chinmaybl wrote:

Hi Guys I am trying to use this macro ..


Sub testingaverage()
Set rng = ActiveSheet.UsedRange
lastRow = rng.Rows(rng.Rows.Count).Row
For i = 1 To lastRow Step 100
Cells(i, "L").FormulaArray = "=Average(f1:f100)"
Next
End Sub


This macro gives me average for F1:F100 in every 100th row of column
L.


What I want to do is :
----the first time I get average it should be F1:F100
----second time It should be F101:F200
---Third time F201:F300 ....... and so on .....


So basically my question is how do I change the x value in Fx


Any help would be great


Thanks
Chinmay


--

Dave Peterson


That was too good ...it works ...Thanks a million ...!!!!!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
array transpose for dynamic data without macros Rad131304 Excel Discussion (Misc queries) 7 February 18th 10 10:48 PM
Array formula: how to join 2 ranges together to form one array? Rich_84 Excel Worksheet Functions 2 April 1st 09 06:38 PM
Excel Array Formula? Tzy New Users to Excel 1 July 17th 08 04:31 PM
Excel XP VBA Array formula SMS - John Howard Excel Programming 2 August 3rd 05 12:07 PM
Tricky array formula issue - Using array formula on one cell, then autofilling down a range aspenbordr Excel Programming 0 July 27th 05 03:59 PM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"