Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Selecting Various Ranges

I want to be able to select a various range from one column and
average the numbers. Then, paste the average to a different cell.

For example:
Select cells F4 thru F12, then average
Paste average value in cell J4
Select cells F13 thru F21, then average
Paste average value in cel J5

Always the same # of cells to select, and always putting the average
in the next cell in the "J" column. I need to do this for about 50
iterations. Can anyone offer some assistance?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Selecting Various Ranges

Hi,

Maybe something like this:

Sub test()
Dim rng As Range
Dim rngTarget As Range
Dim iCellsCount As Integer
Dim i As Integer

'starting cell to be averaged
Set rng = Range("F4")
'number of cells to include in average
iCellsCount = 9
'starting cell for output
Set rngTarget = Range("J4")

For i = 1 To 50
If WorksheetFunction.Sum(rng.Resize(iCellsCount)) 0 Then
rngTarget.Value =
WorksheetFunction.Average(rng.Resize(iCellsCount))
Else
rngTarget.Value = 0
End If
Set rngTarget = rngTarget.Offset(1)
Set rng = rng.Offset(iCellsCount)
Next i


End Sub


You can also do it without VBA. For example, enter this formula in J4 and
copy down as needed.

=IF(SUM(OFFSET($F$4,(ROW()-4)*9, 0, 9, 1))0,
AVERAGE(OFFSET($F$4,(ROW()-4)*9,0,9,1)), 0)



--
Hope that helps.

Vergel Adriano


" wrote:

I want to be able to select a various range from one column and
average the numbers. Then, paste the average to a different cell.

For example:
Select cells F4 thru F12, then average
Paste average value in cell J4
Select cells F13 thru F21, then average
Paste average value in cel J5

Always the same # of cells to select, and always putting the average
in the next cell in the "J" column. I need to do this for about 50
iterations. Can anyone offer some assistance?

Thanks.


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
Built-in for Selecting Ranges? jdawson Excel Programming 2 March 6th 06 08:01 PM
Selecting Ranges Barb Reinhardt Excel Programming 3 February 7th 06 07:23 PM
Selecting ranges Steve Wood Excel Programming 1 August 24th 04 02:16 PM
V.B selecting ranges for naming ice_cool[_2_] Excel Programming 2 March 5th 04 02:21 PM
selecting ranges MDC Excel Programming 1 July 24th 03 03:34 PM


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