PC Review


Reply
Thread Tools Rate Thread

Calculating Average using a Variable Range

 
 
VistaOnMyMac :)
Guest
Posts: n/a
 
      27th Mar 2008
I need to use the average function in the row after the last row of data in
column B that calculates the average of range (B10:last cell of data in that
column). Then I need to fill that row to the right with that same average
function, stopping the fill at the last column of data.

This spreadsheet for my teachers will vary in size and my novice ability
with VB has me stuck. I would really appreciate any help with this.

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      27th Mar 2008
Public Sub ProcessData()
Dim LastRow As Long
Dim LastCol As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
LastCol = .Cells(10, .Columns.Count).End(xlToLeft).Column
.Cells(LastRow + 1, "B").Resize(, LastCol - 1).Formula =
"=AVERAGE(B10:B" & LastRow & ")"
End With

End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"VistaOnMyMac " <VistaOnMyMac @discussions.microsoft.com> wrote in
message news:31191B0D-54A0-4407-AF9D-(E-Mail Removed)...
>I need to use the average function in the row after the last row of data in
> column B that calculates the average of range (B10:last cell of data in
> that
> column). Then I need to fill that row to the right with that same average
> function, stopping the fill at the last column of data.
>
> This spreadsheet for my teachers will vary in size and my novice ability
> with VB has me stuck. I would really appreciate any help with this.
>



 
Reply With Quote
 
VistaOnMyMac :)
Guest
Posts: n/a
 
      28th Mar 2008
Bob,

Thank you so much. It worked great! How would I add formatting tasks to
the same cells. For example:
..NumberFormat = "0.0"

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      29th Mar 2008
Public Sub ProcessData()
Dim LastRow As Long
Dim LastCol As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
LastCol = .Cells(10, .Columns.Count).End(xlToLeft).Column
With .Cells(LastRow + 1, "B").Resize(, LastCol - 1)

.Formula = "=AVERAGE(B10:B" & LastRow & ")"
.NumberFormat = "0.0"
End With
End With

End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"VistaOnMyMac " <(E-Mail Removed)> wrote in message
news:CCEA7013-137F-4A14-88FB-(E-Mail Removed)...
> Bob,
>
> Thank you so much. It worked great! How would I add formatting tasks to
> the same cells. For example:
> .NumberFormat = "0.0"
>



 
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
sub for calculating distance via post code / variable range. Atishoo Microsoft Excel Programming 7 4th Jul 2009 03:34 PM
Calculating average of average Lars Brownie Microsoft Access 3 18th Apr 2008 07:36 PM
Calculating an average from SQL =?Utf-8?B?c2N1YmFkaXZlcg==?= Microsoft Access VBA Modules 0 27th Sep 2006 11:43 AM
Calculating Average on variable sized datasets w/VBA nano Microsoft Excel Programming 1 3rd Feb 2004 02:36 AM
Calculating average of range of cells which keeps moving Davy Microsoft Excel Worksheet Functions 1 10th Jul 2003 03:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:46 PM.