![]() |
Macro code please
Some help please. upon the running of a macro I would like to be able to
display in a message box the sum of numbers in the seven cells above the active cell and also the average of the sum of the same cells that contain a number greater than zero. TIA Neal |
Macro code please
Here you go.
Sub last7() sumtotal = 0 countofaverages = 0 averagetotal = 0 For i = 1 To 7 sumtotal = ActiveCell.Offset(-i, currentcolumn).Value + sumtotal If ActiveCell.Offset(-i, currentcolumn).Value 0 Then averagetotal = ActiveCell.Offset(-i, currentcolumn).Value + averagetotal countofaverages = 1 + countofaverages End If Next i MsgBox "Sum: " & sumtotal t = averagetotal / countofaverages MsgBox "Average: " & t End Sub |
All times are GMT +1. The time now is 03:04 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com