#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 251
Default Macro

I recorded the macro below which needs a little editing and I don't know how
to do it. What I want it to do is average the numbers above the cell
selected starting with the first number below the first blank cell above the
cell selected. That sounds complicated! For example, the cell selected is
D107. D102 is a blank cell. There are numbers in 103 to 106. I want the
macro to run so that it will average the numbers in those cells above. If I
place the cursor in D101 and there are numbers in D77 to D100, then I want it
to average those numbers. I've added an additional step in the macro after
that, but that part of the macro is running fine. It's just that when I
recorded the macro I selected D77 to D100 to average it in D101, and now each
time I run the macro it averages the same number of cells as when I recorded
the macro. If no one answers this, I don't blame you because I am probably
not explaining it very well. Here's the macro, if you can make any heads or
tails about it!! I believe it's just the first line in the macro that needs
editing. Connie

Sub AVERAGE()
'
' AVERAGE Macro
' Macro recorded 5/14/2008 by Connie Martin
'

'
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-24]C:R[-1]C)"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-4]/30"
ActiveCell.Select
Selection.NumberFormat = "0"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 251
Default Macro

I'm sorry. Please ignore this post. This is too complicated. I will try
something else. Sorry if anyone has spent time on this. Connie

"Connie Martin" wrote:

I recorded the macro below which needs a little editing and I don't know how
to do it. What I want it to do is average the numbers above the cell
selected starting with the first number below the first blank cell above the
cell selected. That sounds complicated! For example, the cell selected is
D107. D102 is a blank cell. There are numbers in 103 to 106. I want the
macro to run so that it will average the numbers in those cells above. If I
place the cursor in D101 and there are numbers in D77 to D100, then I want it
to average those numbers. I've added an additional step in the macro after
that, but that part of the macro is running fine. It's just that when I
recorded the macro I selected D77 to D100 to average it in D101, and now each
time I run the macro it averages the same number of cells as when I recorded
the macro. If no one answers this, I don't blame you because I am probably
not explaining it very well. Here's the macro, if you can make any heads or
tails about it!! I believe it's just the first line in the macro that needs
editing. Connie

Sub AVERAGE()
'
' AVERAGE Macro
' Macro recorded 5/14/2008 by Connie Martin
'

'
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-24]C:R[-1]C)"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-4]/30"
ActiveCell.Select
Selection.NumberFormat = "0"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 186
Default Macro

Hi Connie,
You might try the following macro:

Option Explicit
Dim Anchor As Double
Dim Iloop As Double
Dim Rowcount As Double
Sub Compute_Avg()

'Turn off warnings, etc.
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Rowcount = Cells(Rows.Count, "D").End(xlUp).Row
Anchor = 1
For Iloop = 2 To Rowcount
If IsEmpty(Cells(Iloop, "D")) Then
Cells(Iloop, "D") = "=Average(D" & Anchor & ":D" & Iloop - 1 & ")"
Anchor = Iloop + 1
End If
Next Iloop
Cells(Rowcount + 1, "D") = "=Average(D" & Anchor & ":D" & Iloop - 1 & ")"

'Turn on warnings, etc.
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

--
Ken Hudson


"Connie Martin" wrote:

I recorded the macro below which needs a little editing and I don't know how
to do it. What I want it to do is average the numbers above the cell
selected starting with the first number below the first blank cell above the
cell selected. That sounds complicated! For example, the cell selected is
D107. D102 is a blank cell. There are numbers in 103 to 106. I want the
macro to run so that it will average the numbers in those cells above. If I
place the cursor in D101 and there are numbers in D77 to D100, then I want it
to average those numbers. I've added an additional step in the macro after
that, but that part of the macro is running fine. It's just that when I
recorded the macro I selected D77 to D100 to average it in D101, and now each
time I run the macro it averages the same number of cells as when I recorded
the macro. If no one answers this, I don't blame you because I am probably
not explaining it very well. Here's the macro, if you can make any heads or
tails about it!! I believe it's just the first line in the macro that needs
editing. Connie

Sub AVERAGE()
'
' AVERAGE Macro
' Macro recorded 5/14/2008 by Connie Martin
'

'
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-24]C:R[-1]C)"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-4]/30"
ActiveCell.Select
Selection.NumberFormat = "0"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 251
Default Macro

Ken, that macro works fabulously! It throws some zeros in empty cells but
that's easy to rectify. It does the whole sheet in one click on the mouse!
Thank you! You are fabulous. The fact that you even understood my jumble is
something else, and then to come up with the answer!! Wow! I'm impressed!
Thank you so much! Connie


"Ken Hudson" wrote:

Hi Connie,
You might try the following macro:

Option Explicit
Dim Anchor As Double
Dim Iloop As Double
Dim Rowcount As Double
Sub Compute_Avg()

'Turn off warnings, etc.
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Rowcount = Cells(Rows.Count, "D").End(xlUp).Row
Anchor = 1
For Iloop = 2 To Rowcount
If IsEmpty(Cells(Iloop, "D")) Then
Cells(Iloop, "D") = "=Average(D" & Anchor & ":D" & Iloop - 1 & ")"
Anchor = Iloop + 1
End If
Next Iloop
Cells(Rowcount + 1, "D") = "=Average(D" & Anchor & ":D" & Iloop - 1 & ")"

'Turn on warnings, etc.
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

--
Ken Hudson


"Connie Martin" wrote:

I recorded the macro below which needs a little editing and I don't know how
to do it. What I want it to do is average the numbers above the cell
selected starting with the first number below the first blank cell above the
cell selected. That sounds complicated! For example, the cell selected is
D107. D102 is a blank cell. There are numbers in 103 to 106. I want the
macro to run so that it will average the numbers in those cells above. If I
place the cursor in D101 and there are numbers in D77 to D100, then I want it
to average those numbers. I've added an additional step in the macro after
that, but that part of the macro is running fine. It's just that when I
recorded the macro I selected D77 to D100 to average it in D101, and now each
time I run the macro it averages the same number of cells as when I recorded
the macro. If no one answers this, I don't blame you because I am probably
not explaining it very well. Here's the macro, if you can make any heads or
tails about it!! I believe it's just the first line in the macro that needs
editing. Connie

Sub AVERAGE()
'
' AVERAGE Macro
' Macro recorded 5/14/2008 by Connie Martin
'

'
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-24]C:R[-1]C)"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-4]/30"
ActiveCell.Select
Selection.NumberFormat = "0"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 88
Default Macro

instead of creating a macro, just type the formula into the cell. creating a
macro for something this simple is too intensive for any user, plus if the
cells that you want to average out changes, you will have to change the
macro. the time invested in changing the macro could be better used to just
do the following:

the formulate that you want, if you want to document the average onto the
spreadsheet, is =average(select your cells)
or you can just select your cells, and look at the bottom it will show a
total and average for what you have selected.

jat



"Connie Martin" wrote:

I recorded the macro below which needs a little editing and I don't know how
to do it. What I want it to do is average the numbers above the cell
selected starting with the first number below the first blank cell above the
cell selected. That sounds complicated! For example, the cell selected is
D107. D102 is a blank cell. There are numbers in 103 to 106. I want the
macro to run so that it will average the numbers in those cells above. If I
place the cursor in D101 and there are numbers in D77 to D100, then I want it
to average those numbers. I've added an additional step in the macro after
that, but that part of the macro is running fine. It's just that when I
recorded the macro I selected D77 to D100 to average it in D101, and now each
time I run the macro it averages the same number of cells as when I recorded
the macro. If no one answers this, I don't blame you because I am probably
not explaining it very well. Here's the macro, if you can make any heads or
tails about it!! I believe it's just the first line in the macro that needs
editing. Connie

Sub AVERAGE()
'
' AVERAGE Macro
' Macro recorded 5/14/2008 by Connie Martin
'

'
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-24]C:R[-1]C)"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-4]/30"
ActiveCell.Select
Selection.NumberFormat = "0"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 251
Default Macro

Thank you for replying to my jumble. However, this spreadsheet is hundreds
of rows long. To stop and put in an average formula at different intervals
all the way down would be tedious. If I could just click on the cell and
click on a macro button, it would've been so much easier. However, I have
changed my spreadsheet. Just the same, I will see what Ken Hudson's macro
looks like. Thank you once again for even taking the time to read my lengthy
dilemma! Connie

"jatman" wrote:

instead of creating a macro, just type the formula into the cell. creating a
macro for something this simple is too intensive for any user, plus if the
cells that you want to average out changes, you will have to change the
macro. the time invested in changing the macro could be better used to just
do the following:

the formulate that you want, if you want to document the average onto the
spreadsheet, is =average(select your cells)
or you can just select your cells, and look at the bottom it will show a
total and average for what you have selected.

jat



"Connie Martin" wrote:

I recorded the macro below which needs a little editing and I don't know how
to do it. What I want it to do is average the numbers above the cell
selected starting with the first number below the first blank cell above the
cell selected. That sounds complicated! For example, the cell selected is
D107. D102 is a blank cell. There are numbers in 103 to 106. I want the
macro to run so that it will average the numbers in those cells above. If I
place the cursor in D101 and there are numbers in D77 to D100, then I want it
to average those numbers. I've added an additional step in the macro after
that, but that part of the macro is running fine. It's just that when I
recorded the macro I selected D77 to D100 to average it in D101, and now each
time I run the macro it averages the same number of cells as when I recorded
the macro. If no one answers this, I don't blame you because I am probably
not explaining it very well. Here's the macro, if you can make any heads or
tails about it!! I believe it's just the first line in the macro that needs
editing. Connie

Sub AVERAGE()
'
' AVERAGE Macro
' Macro recorded 5/14/2008 by Connie Martin
'

'
ActiveCell.FormulaR1C1 = "=AVERAGE(R[-24]C:R[-1]C)"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-4]/30"
ActiveCell.Select
Selection.NumberFormat = "0"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

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
need help to update macro to office 2007 macro enabled workbook jatman Excel Discussion (Misc queries) 1 December 14th 07 01:57 PM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM


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