Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calculating Average using a Variable Range

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Calculating Average using a Variable Range

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 wrote in
message ...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calculating Average using a Variable Range

Bob,

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Calculating Average using a Variable Range

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 :)" wrote in message
...
Bob,

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



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
Calculating an average Maggie Excel Worksheet Functions 1 August 22nd 08 03:50 AM
Calculating Average ub Excel Discussion (Misc queries) 2 July 16th 08 05:14 PM
Calculating an average using VBA Ben Excel Programming 2 August 2nd 07 09:26 PM
Calculating the average Andy_Trow Excel Discussion (Misc queries) 3 July 27th 07 02:15 PM
Calculating Average on variable sized datasets w/VBA nano Excel Programming 1 February 3rd 04 02:36 AM


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