Simple macros question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have written a short macros to sample and average data sets and post the
average to a separate cell. I have the macros to repeat 100 times, 100
averages, but don't know how to have it post each average to a progressive
cell. In other words, post the first average to one cell, then index down
for the next average and next,... till there is a list of 100 averages.
After that, I will do more with the data, but need to get by this step first.
 
Let's say that the cell where you put the first average is "B1"
You have a macro function getAverage
then try the following

dim avg as double
dim r as integer
dim cB1 as range
set cB1 = range ("B1")
for r = 1 to 100
avg=getAverage
cB1.Offset(r,0).value=avg
next r
 
Thanks, I'll give it a try.

Martin Krastev said:
Let's say that the cell where you put the first average is "B1"
You have a macro function getAverage
then try the following

dim avg as double
dim r as integer
dim cB1 as range
set cB1 = range ("B1")
for r = 1 to 100
avg=getAverage
cB1.Offset(r,0).value=avg
next r
 
Use a for loop if you know how many times you need to iterate.

For i = 1 to 100
Range("C" & i & "").Select
ActiveCell.FormulaR1C1 = "=AVERAGE("A" & i & ":B" & i & "")"
Next


This assumes A(i) and B(i) hold the numbers you want averaged and the
result is placed in C(i)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top