Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default I have a created a variable with a loop, how do I find average

On 11 Jul., 02:39, wrote:
that was defintiely helpful, how would you change it if you added a
second variable. look below at the example. it is incorrectly taking
scores from previous weeks. is there a way to clear the variable, once
it is captured

Sub rndgenandaver()
Dim score, t, lastt, averagescore, n, numberofweeks
t = 1
lastt = 16
n = 1
numberofweeks = 16
ReDim score(lastt, numberofweeks), averagescore(numberofweeks)
n = 1
For n = 1 To numberofweeks
t = 1
For t = 1 To lastt
If t 0 Then score(t, n) = Rnd()
Worksheets("Sheet1").Cells(t, n) = score(t, n)
Next t
averagescore(n) = Application.Average(score)
Worksheets("Sheet1").Cells(112, n) = averagescore(n)
Next n
End Sub


Hi

You don't need a two-dimensional array. Just re-use a one dimensional
array. Try this:

Sub rndgenandaver()
Dim Score()
Dim LastT As Integer
Dim AverageScore()
Dim NumberOfWeeks As Integer
Dim t As Integer
Dim n As Integer

LastT = 16
NumberOfWeeks = 16
ReDim Score(LastT), AverageScore(NumberOfWeeks)

For n = 1 To NumberOfWeeks
For t = 1 To LastT
Score(t) = Rnd()
Worksheets("Sheet1").Cells(t, n) = Score(t)
Next
AverageScore(n) = Application.Average(Score)
Worksheets("Sheet1").Cells(112, n) = AverageScore(n)
Next
End Sub

Best regards,
Per
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
I have a created a variable with a loop, how do I find average ofvariable most efficiently? [email protected] Excel Programming 0 July 10th 08 08:42 PM
Find monthly average but have average automatically configured kimbafred Excel Discussion (Misc queries) 2 August 8th 07 12:28 AM
two variable dates created from a single date Lindsay New Users to Excel 3 August 3rd 07 10:36 PM
For Each ... Next loop - need to reference the loop variable [email protected] Excel Programming 4 July 13th 06 06:12 PM
inadvertently created loop marianne Excel Programming 4 May 19th 06 01:04 PM


All times are GMT +1. The time now is 03:11 AM.

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

About Us

"It's about Microsoft Excel"