Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default calculate average from multiple columns and put results in a new s

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default calculate average from multiple columns and put results in a new s

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default calculate average from multiple columns and put results in a new s

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default calculate average from multiple columns and put results in a n

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
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
how do i calculate the average of 30+ cells over multiple workshee Ariana Excel Worksheet Functions 4 July 9th 08 11:44 PM
Calculate Average Accross Multiple Worksheets JK Excel Discussion (Misc queries) 1 May 3rd 07 05:34 PM
Calculate average in a cell from one of two columns BillO Excel Worksheet Functions 2 April 13th 07 01:54 AM
Calculate multiple results from multiple input values? Jetta1515 Excel Discussion (Misc queries) 5 June 1st 06 03:09 PM
Looking-up Columns w/calc'd Values ONLY to Calculate Average sony654 Excel Worksheet Functions 5 April 21st 06 06:21 AM


All times are GMT +1. The time now is 06:31 AM.

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"