Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PP PP is offline
external usenet poster
 
Posts: 3
Default Average per block

Hi all,

Could anyone help me in solving this problem.

I have a dataset in one column (G) containing only numbers. Every nth
row in that column is empty (so it varies). In this empty cell I want
to calculate the average of the n cells above. n is defined by the next
empty row. The data looks like this:
G
3
3
3
empty
3
3
empty
3
3
3
3
3
empty

My question is: Is there a VBA-sollution to insert an average in every
empty cell and where the average is based on the n cells above untill
its hits another empty cell.

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,726
Default Average per block

Public Sub ProcessData()
Const TEST_COLUMN As String = "G" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
Dim istart As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
istart = 1
For i = 2 To iLastRow + 1
If .Cells(i, TEST_COLUMN).Value = "" Then
.Cells(i, TEST_COLUMN).Value =
Application.Average(.Cells(istart, TEST_COLUMN).Resize(i - istart + 1))
istart = i + 1
End If
Next i

End With

End Sub

--
HTH

Bob

(change the xxxx to gmail if mailing direct)
"PP" wrote in message
ups.com...
Hi all,

Could anyone help me in solving this problem.

I have a dataset in one column (G) containing only numbers. Every nth
row in that column is empty (so it varies). In this empty cell I want
to calculate the average of the n cells above. n is defined by the next
empty row. The data looks like this:
G
3
3
3
empty
3
3
empty
3
3
3
3
3
empty

My question is: Is there a VBA-sollution to insert an average in every
empty cell and where the average is based on the n cells above untill
its hits another empty cell.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PP PP is offline
external usenet poster
 
Posts: 3
Default Average per block

Dear Bob,

Thanks very much for your reply. It works great. Since I am a newbe on
VBA I knew this was possible, just not on how to program it.

Still, I was wondering if it is possible to modify the code in such a
way that instead of calculating the average underneath the blocks, it
calculates it above the blocks. I've tried to alter some plus and minus
signs, but that didn't work.

Thanks,
Pim

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,726
Default Average per block

Assuming that there is a blank at the top

Public Sub ProcessData()
Const TEST_COLUMN As String = "G" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
Dim iStart As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
iStart = iLastRow
For i = iLastRow To 1 Step -1
If .Cells(i, TEST_COLUMN).Value = "" Then
.Cells(i, TEST_COLUMN).Value = Application.Average _
(.Cells(i + 1, TEST_COLUMN).Resize(iStart - i))
iStart = i - 1
End If
Next i

End With

End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"PP" wrote in message
ps.com...
Dear Bob,

Thanks very much for your reply. It works great. Since I am a newbe on
VBA I knew this was possible, just not on how to program it.

Still, I was wondering if it is possible to modify the code in such a
way that instead of calculating the average underneath the blocks, it
calculates it above the blocks. I've tried to alter some plus and minus
signs, but that didn't work.

Thanks,
Pim



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PP PP is offline
external usenet poster
 
Posts: 3
Default Average per block

Dear Bob,

many thanx!! You safed me a ton load of boring work!

I first had to cut your commentline and paste on a new line underneath
the line. On the Windowsmachine I used this afternoon this wasn't
necessary, but on my Mac this was... .

Again many thanx!
Pim

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
rolling average William Okumu Excel Worksheet Functions 5 May 25th 06 03:49 PM
Modified Average Function PA Excel Worksheet Functions 3 May 15th 06 12:20 PM
plotted Average Micayla Bergen Charts and Charting in Excel 4 July 15th 05 12:13 PM
What is this kind of average called? havocdragon Excel Worksheet Functions 3 June 24th 05 05:10 PM
Average the Last Five Cells in a Column Warrior Princess Excel Worksheet Functions 3 March 16th 05 02:12 PM


All times are GMT +1. The time now is 01:25 PM.

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"