Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default copy formula with adding e.g. 10 cells

Hello,

I've got a data sheet with 1000 values (A1:J100). I would like to calculate
the average of every 10th value in the "A" colomn. This will be the average
A1:J1; A10:J10;A20:J20 etc I want to transport these average values to sheet
2. Is there anyone who can help me with this case? I want to prevent to make
a formula 100 times by doing this manual.

René


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default copy formula with adding e.g. 10 cells

Hi René,

You can use the code below to get your results. Add the code to a module in
your workbook. Make sure that you have worksheets named "Sheet1" and
"Sheet2". This will return the AVERAGE of the 10th rows to Sheet2.

Hope that helps.

Regards,
James

Sub CalculateAverages()
Dim wkb As Workbook
Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim rng As Range
Dim i As Integer

' Set a reference to the current Workbook.
Set wkb = ThisWorkbook
' Set a reference to Sheet1.
Set wks1 = wkb.Worksheets("Sheet1")
' Set a reference to Sheet2.
Set wks2 = wkb.Worksheets("Sheet2")
' Set a Cell starting point in Worksheet 2 for where the
' results will be placed.
Set rng = wks2.Range("A1")

For i = 0 To 10
If i = 0 Then
' In the first loop i = 0, but the Row reference needs to be
' set to "1".
rng.Formula = "=AVERAGE(Sheet1!A1:J1)"
Else
' All other Rows can be found by multiplying "i" by 10.
rng.Formula = "=AVERAGE(Sheet1!A" & i * 10 & ":J" & i * 10 & ")"
End If
' Move to the next Cell down in Worksheet 2.
Set rng = rng.Offset(1, 0)
Next i

Set wkb = Nothing
Set wks1 = Nothing
Set wks2 = Nothing
Set rng = Nothing

MsgBox "DONE"
End Sub

"René" wrote:

Hello,

I've got a data sheet with 1000 values (A1:J100). I would like to calculate
the average of every 10th value in the "A" colomn. This will be the average
A1:J1; A10:J10;A20:J20 etc I want to transport these average values to sheet
2. Is there anyone who can help me with this case? I want to prevent to make
a formula 100 times by doing this manual.

René


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default copy formula with adding e.g. 10 cells

Thanks a lot!!!!!!

"JS2004R6" wrote:

Hi René,

You can use the code below to get your results. Add the code to a module in
your workbook. Make sure that you have worksheets named "Sheet1" and
"Sheet2". This will return the AVERAGE of the 10th rows to Sheet2.

Hope that helps.

Regards,
James

Sub CalculateAverages()
Dim wkb As Workbook
Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim rng As Range
Dim i As Integer

' Set a reference to the current Workbook.
Set wkb = ThisWorkbook
' Set a reference to Sheet1.
Set wks1 = wkb.Worksheets("Sheet1")
' Set a reference to Sheet2.
Set wks2 = wkb.Worksheets("Sheet2")
' Set a Cell starting point in Worksheet 2 for where the
' results will be placed.
Set rng = wks2.Range("A1")

For i = 0 To 10
If i = 0 Then
' In the first loop i = 0, but the Row reference needs to be
' set to "1".
rng.Formula = "=AVERAGE(Sheet1!A1:J1)"
Else
' All other Rows can be found by multiplying "i" by 10.
rng.Formula = "=AVERAGE(Sheet1!A" & i * 10 & ":J" & i * 10 & ")"
End If
' Move to the next Cell down in Worksheet 2.
Set rng = rng.Offset(1, 0)
Next i

Set wkb = Nothing
Set wks1 = Nothing
Set wks2 = Nothing
Set rng = Nothing

MsgBox "DONE"
End Sub

"René" wrote:

Hello,

I've got a data sheet with 1000 values (A1:J100). I would like to calculate
the average of every 10th value in the "A" colomn. This will be the average
A1:J1; A10:J10;A20:J20 etc I want to transport these average values to sheet
2. Is there anyone who can help me with this case? I want to prevent to make
a formula 100 times by doing this manual.

René


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default copy formula with adding e.g. 10 cells

James, it works!!! Once again thanks!

"René" wrote:

Hello,

I've got a data sheet with 1000 values (A1:J100). I would like to calculate
the average of every 10th value in the "A" colomn. This will be the average
A1:J1; A10:J10;A20:J20 etc I want to transport these average values to sheet
2. Is there anyone who can help me with this case? I want to prevent to make
a formula 100 times by doing this manual.

René


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
Automatically copy formula in column when adding new row.... Jasmine R Excel Worksheet Functions 2 March 31st 10 06:24 PM
adding cells that contain a formula jbishard Excel Discussion (Misc queries) 3 March 24th 09 08:18 PM
Can I use a formula to copy info while adding a whole new row? cdcam Excel Discussion (Misc queries) 1 November 25th 08 05:06 AM
Formula for Adding cells up Raich Excel Worksheet Functions 1 July 26th 08 10:15 AM
Copy/Paste how to avoid the copy of formula cells w/o calc values Dennis Excel Discussion (Misc queries) 10 March 2nd 06 10:47 PM


All times are GMT +1. The time now is 11:48 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"