Consulting

Results 1 to 18 of 18

Thread: Solved: Summing time in a dynamic range?

  1. #1
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location

    Solved: Summing time in a dynamic range?

    Hi all, i have a column which has many different times shown in this format 00:00:00, some may show 30 mins like 00:30:00 some may show 1Hr30Mins like 01:30:00 etc there are never any seconds (just the column is formatted as time!) all these times are amounts of hours and minutes worked on certain tasks, the tasks are paid by the hour.

    My problem is when i SUM the column i don't get the correct amount of hours and minutes, i would like to find out the amount of wages for the range so if the range is called WorkedTime i want to multiply it by the amount of pay to find the expected wages, lets say the wages are ?8/hr

    i can custom format the cell containing the formula to [h]mm:ss and then when i use =Sum(WorkedTime) i get the correct amount of hours and minutes but i am having trouble showing the actual wage!

    Any ideas?

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post your workbook so we can see the formats you're using?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Simon,

    Times in Excel are actually fractions of days. Just convert your numbers to a real number format and you'll see what I mean. Today, for example, is 39120, and noon on that would be 39120.5

    Try taking your "hours" and multiplying it by 24 in your formula. It should probably do it for you.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try formatting both your data and formula as [hh]:mm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Ken i couldnt make it work....the workbook is attached as you will i have other plans and probably questions for the workbook when i get this over and done with!

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    As Ken says, hours are still part of a day, even in your formula. To get the total cost use
    =SUM(WorkedTime)*8*24
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Simon,

    In I2:

    =I1*8*24

    Change the number format to $ or , or something (not time)

    Is that what you mean?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Malcom thanks for continuing with the responses yours came up with just an increased minute amount, Kens suggestion gave the correct amount (of course i have to leave the original formula cell intact and use one underneath!) once i formatted the cell as currency.

    Thanks for the help............my next task now is to get the wages to work by month, i'm thinking of using an array formula for that something like
    =IF(ROWS($C$2:CC2)<=COUNTIF('Client Time Sheet'!$B$2:$B$80,$E$2),INDEX(WorkedTime,SMALL(IF('Client Time Sheet'!$B$2:$B$80=$E$2,ROW('Client Time Sheet'!$B$2:$B$80)-ROW($A$2)+1),ROW(A1))),"")
    copied down it should show me all the matches for a date i set in E2............still needs playing around with!

    Again thanks!

    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  9. #9
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by Simon Lloyd
    Malcom thanks for continuing with the responses yours came up with just an increased minute amount, Kens suggestion gave the correct amount (of course i have to leave the original formula cell intact and use one underneath!) once i formatted the cell as currency.
    Actually, no... You're right in that my solution as given needs to keep your cell there, but Malcolm's works. Format Malcolm's answer as a number (not time), and you'll see that it gives the same result.

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  10. #10
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    =IF(ROWS($C$2:CC2)<=COUNTIF('Client Time Sheet'!$B$2:$B$80,$E$2),INDEX(WorkedTime,SMALL(IF('Client Time Sheet'!$B$2:$B$80=$E$2,ROW('Client Time Sheet'!$B$2:$B$80)-ROW($A$2)+1),ROW(A1))),"")
    You could try this non-array approach.

    Input formula in worksheet tab name "My Wage By Month" in cell F2 and copied down.

    =IF(ROW()>ROW(F$1)+COUNTIF('Client Time Sheet'!$B$2:$B$80,$E$2),"",INDEX('Client Time Sheet'!$E$2:$E$80,MATCH($E$2,'Client Time Sheet'!$B$2:$B$80,0)+ROW()-ROW(F$2)))
    SHAZAM!

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Simon Lloyd
    Thanks for the help............my next task now is to get the wages to work by month, i'm thinking of using an array formula for that something like copied down it should show me all the matches for a date i set in E2............still needs playing around with it.
    It's simpler than that is it not?

    =SUMPRODUCT(--(MONTH($B$2:$B$1000)=ROW(A1)),$E$2:$E$1000)*24*8

    for January, just copy down for Feb etc.

  12. #12
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Thanks for the replies, if you look at the sheet i intend to develop for summing hours and wages by month i have titles: Date | Hours | Average Wage, i am working on a formula to put in the hours column to calculate hours for a month the formula seemed to work (but of course summed all the hours so far because of SUM(WorkedTime), the formula , i thought relied on the value in A2 to be between 2 dates to produce a result however removing the value from A2 didnt change the result.

    =IF(AND(OR($A2>="01/01/07",$A2<="31/01/07")),SUM(WorkedTime),0)
    My ideal formula would be: IF Ax contained a month name Like "January" THEN SUM WorkedTime (column E) FOR all ROWS that fall in that month, somethin like
    =IF(A2=MONTH,SUM(ALL ROWS MATCHING MONTH ON CLIENT SHEET),0) although i wish it was this simple!

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  13. #13
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Ok i removed the OR statement and it now makes a difference if there is a value in A2 however the value has to be text !

    Still doesnt work of course as i want

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    .

  15. #15
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Bob not checked out your attachment yet but i was fiddling with this
    =IF(AND($A2>="01 January 2007",$A2<="31 January 2007"),SUM(ROWS({"01 January 2007","31 January 2007"})),0)
    which if the date fell between those in the formula it returned a value of 1 if it fell outside of the dates it returned a value of 0, i am assuming its because it is only checking for the occurrence of the date and counting the amount of times.....although i'm probably way of mark!

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  16. #16
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Just checked it out ...nice!, i tried to look for "dd/mmm/yyyy" never thought of looking for "mmmm" and also didnt think of using the TEXT function to look for it!

    Thanks for the solution!, saves me hours 'n' hours and of course loads of questions!

    This workbook is for my partner i intend to automate as much as possible, add a userform for client entry and finding clients and details, and more columns for added information, right now she has a bag full of pieces of crumpled paper! - not good!

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  17. #17
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to learn the joys of SUMPRODUCT.

    SUMIF is great for doing conditional sums such as this, but it struggles with partial comparisons, whereas SUMPRODUCT gobbles these up.

  18. #18
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I had a look at SUMPRODUCT() but then i got a bit put off because of the need for arrays in this and haven't got my head on straight for working the relationship between what i excpected from my data and translating that to the array!

    Remember Bob...Bungalows.....Skyscrapers are a way off!

    Lol

    Kind Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •