Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Time if/then caclculate average formula?

Hello,

I have been keeping track of my blood pressure with an Excel
spreadsheet. I list "date" on column A, "time" on column B, "Systolic"
on column C, "Dia" on column D, and "Pulse" on column E (Columns A, B,
C, D, E). Currently I have a formula to give an overall average of
column C in one box, Column D in another, and Column E in another.

I want to add an Average box for each column C, D, and E based on the
time of day (column B) to include only if they are readings between a
certain time (for example, time is after 5 PM but before midnight).
Does someone here know how to do this?

Any help with this would be much appreciated.

Thanks!

Tom

--
http://www.rvlover.net
http://weather.rvlover.net


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,091
Default Time if/then caclculate average formula?

How would you do it on paper? If we have your paper formula, we can tell you
how to do it in Excel.

Tyro

"Tom T" wrote in message
...
Hello,

I have been keeping track of my blood pressure with an Excel spreadsheet.
I list "date" on column A, "time" on column B, "Systolic" on column C,
"Dia" on column D, and "Pulse" on column E (Columns A, B, C, D, E).
Currently I have a formula to give an overall average of column C in one
box, Column D in another, and Column E in another.

I want to add an Average box for each column C, D, and E based on the
time of day (column B) to include only if they are readings between a
certain time (for example, time is after 5 PM but before midnight). Does
someone here know how to do this?

Any help with this would be much appreciated.

Thanks!

Tom

--
http://www.rvlover.net
http://weather.rvlover.net



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Time if/then caclculate average formula?

This VBA code is a little crude because I am not use to working with times,
but it tested OK. I used columns G, H and I to accumulate the readings
between 5pm and 1159pm. You will need to format you column B as time in the
h:mm AM/PM
format for this to work. Even then you might get an error message. But it
is something to play with. I also used celss K2, L2 and M2 to display the
averages,

Sub TODavg()
Dim lr, lr2 As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
Set myRange = Sheets(1).Range("B2:B" & lr)
For Each c In myRange
lr2 = Cells(Rows.Count, 7).End(xlUp).Row
If c.Value = #5:00:00 PM# And c.Value <= #11:59:00 PM# Then
Sheets(1).Range(c.Offset(0, 1), c.Offset(0, 3)).Copy _
Destination:=Sheets(1).Range("G" & lr2 + 1)
End If
Next
Application.CutCopyMode = False
lr3 = Cells(Rows.Count, 7).End(xlUp).Row
Range("K2") = Application.WorksheetFunction.Average(Range("G2:G" & lr3 - 1))
Range("L2") = Application.WorksheetFunction.Average(Range("H2:H" & lr3 - 1))
Range("M2") = Application.WorksheetFunction.Average(Range("I2:I" & lr3 - 1))
End Sub

"Tom T" wrote:

Hello,

I have been keeping track of my blood pressure with an Excel
spreadsheet. I list "date" on column A, "time" on column B, "Systolic"
on column C, "Dia" on column D, and "Pulse" on column E (Columns A, B,
C, D, E). Currently I have a formula to give an overall average of
column C in one box, Column D in another, and Column E in another.

I want to add an Average box for each column C, D, and E based on the
time of day (column B) to include only if they are readings between a
certain time (for example, time is after 5 PM but before midnight).
Does someone here know how to do this?

Any help with this would be much appreciated.

Thanks!

Tom

--
http://www.rvlover.net
http://weather.rvlover.net



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Time if/then caclculate average formula?

Here's another way.

Use a helper column (my example used F) to have a 1 if the time is
within your bounds, otherwise a zero. I put the lower time bound
(05:00:00 PM) in I2, and the upper time bound (11:59:59 PM) in I3.
Midnight doesn't work well because excel uses 0 (zero) for 12:00:00 AM,
so it is hard to tell if a time is less than midnight. Keep that in
mind when you enter your times too.

In F2 put =IF(AND($B2$I$2,$B2<$I$3),1,0) and fill down, say to row 100
or whatever you have data in the other columns. As you adjust your time
bounds in I2 and I3, the cells in F will change to show cells matching
those bounds.
To get the average, use sumproduct to multiply your values in C (or D or
E) by the value (0 or 1) in F. I can't get sumproduct to use the entire
column without a #NUM! error, so I used up to row 100. Adjust as needed.
In your "timed average" cell for Systolic, put
=SUMPRODUCT($C1:$C100,$F1:$F100)/COUNTIF($F1:$F100,1)
For Dia and Pulse, change the $C to $D or $E.

Len

Tom T wrote:
Hello,

I have been keeping track of my blood pressure with an Excel
spreadsheet. I list "date" on column A, "time" on column B, "Systolic"
on column C, "Dia" on column D, and "Pulse" on column E (Columns A, B,
C, D, E). Currently I have a formula to give an overall average of
column C in one box, Column D in another, and Column E in another.

I want to add an Average box for each column C, D, and E based on the
time of day (column B) to include only if they are readings between a
certain time (for example, time is after 5 PM but before midnight).
Does someone here know how to do this?

Any help with this would be much appreciated.

Thanks!

Tom

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
Using a time value in an Excel formula to figure an hourly average Chuck Walsh Excel Discussion (Misc queries) 1 October 23rd 07 09:07 PM
average rate of change per given time period between 2 moments in time of a value David Virgil Hobbs Excel Worksheet Functions 1 December 19th 06 07:24 AM
average rate of change per given time period between 2 moments in time of a value David Virgil Hobbs Excel Programming 1 December 19th 06 07:24 AM
How do I caclculate a ratio where the outcome is X to 1 djerome Excel Worksheet Functions 4 August 30th 06 09:53 PM
how does one convert text to a formula "average(A:A)" to =average( phshirk Excel Worksheet Functions 4 April 14th 05 01:20 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"