PC Review


Reply
Thread Tools Rate Thread

calculate average from multiple columns and put results in a new s

 
 
=?Utf-8?B?dHVyZW4=?=
Guest
Posts: n/a
 
      7th Sep 2007
I have a set of data that have several groups. Each group has three columns
and each column has hundreds of rows. For each row in each group, I want to
calculate the average of the three columns and put the result in a new sheet.
So that each group will have only one column (the average). Can someone
help me how to achieve this using VB script? Thank you very much.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      8th Sep 2007
I'm not sure why you want to do this in VBA when it is very siimple using
excel functions? It can be done in VBA, but it is harder.

You can do an average by simply using the insert function menu item and then
copying the formula down a column like this formula
=AVERAGE(Sheet1!A2:C2)

"turen" wrote:

> I have a set of data that have several groups. Each group has three columns
> and each column has hundreds of rows. For each row in each group, I want to
> calculate the average of the three columns and put the result in a new sheet.
> So that each group will have only one column (the average). Can someone
> help me how to achieve this using VB script? Thank you very much.

 
Reply With Quote
 
=?Utf-8?B?YmFybmFiZWw=?=
Guest
Posts: n/a
 
      8th Sep 2007
If I understand you correctly, your data has group 1 in columns A, B and C
rows 1-X, group 2 in columns D, E and F rows 1-Y, group 3 in rows G, H and I
rows 1-Z

You want a new sheet with the avg of group 1 in column A, avg of group 2 in
col B, avg group 3 in col C and so on. Do you need the values to be live so
that changing the source changes the totals or will you rerun the macro?

Assuming you are going to rerun the macro try this:
Sub GenAvg()

Dim source As Worksheet
Dim target As Worksheet
Dim groupNo As Integer
Dim currRow As Long

Set source = ActiveSheet
Worksheets.Add
Set target = ActiveSheet

groupNo = 1

While Not IsEmpty(source.Cells(1, (groupNo - 1) * 3 + 1))
currRow = 1
While Not IsEmpty(source.Cells(currRow, (groupNo - 1) * 3 + 1))
target.Cells(currRow, groupNo) = (source.Cells(currRow, (groupNo - 1)
* 3 + 1) + source.Cells(currRow, (groupNo - 1) * 3 + 2) +
source.Cells(currRow, (groupNo - 1) * 3 + 3)) / 3
currRow = currRow + 1
Wend
groupNo = groupNo + 1
Wend

End Sub



"turen" wrote:

> I have a set of data that have several groups. Each group has three columns
> and each column has hundreds of rows. For each row in each group, I want to
> calculate the average of the three columns and put the result in a new sheet.
> So that each group will have only one column (the average). Can someone
> help me how to achieve this using VB script? Thank you very much.

 
Reply With Quote
 
=?Utf-8?B?YmFybmFiZWw=?=
Guest
Posts: n/a
 
      8th Sep 2007
I assumed they don't know how many rows there will be in each group and
didn't want extra formulas

"Joel" wrote:

> I'm not sure why you want to do this in VBA when it is very siimple using
> excel functions? It can be done in VBA, but it is harder.
>
> You can do an average by simply using the insert function menu item and then
> copying the formula down a column like this formula
> =AVERAGE(Sheet1!A2:C2)
>
> "turen" wrote:
>
> > I have a set of data that have several groups. Each group has three columns
> > and each column has hundreds of rows. For each row in each group, I want to
> > calculate the average of the three columns and put the result in a new sheet.
> > So that each group will have only one column (the average). Can someone
> > help me how to achieve this using VB script? Thank you very much.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
average multiple columns but skip a few columns cpliu Microsoft Excel Discussion 6 7th Jan 2009 08:01 PM
how do i calculate the average of 30+ cells over multiple workshee Ariana Microsoft Excel Worksheet Functions 4 9th Jul 2008 11:44 PM
Calculate Average Accross Multiple Worksheets =?Utf-8?B?Sks=?= Microsoft Excel Misc 1 3rd May 2007 05:34 PM
Calculate average in a cell from one of two columns =?Utf-8?B?QmlsbE8=?= Microsoft Excel Worksheet Functions 2 13th Apr 2007 01:54 AM
Looking-up Columns w/calc'd Values ONLY to Calculate Average =?Utf-8?B?c29ueTY1NA==?= Microsoft Excel Worksheet Functions 5 21st Apr 2006 06:21 AM


Features
 

Advertising
 

Newsgroups
 


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