+ Reply to Thread
Results 1 to 13 of 13

Calculating Alternating Values

  1. #1
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Calculating Alternating Values

    I have a bunch of start End times in columns calculating total time :-

    Please Login or Register  to view this content.
    Which works great except is there an easy way to adapt this incase someone inserts a column and thevalues start in an even row?

    Or is there a better way?
    Last edited by VBA Noob; 03-06-2009 at 01:59 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Calculating Alternating Values

    Does this fix it?

    Please Login or Register  to view this content.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Calculating Alternating Values

    Almost took the -1 out of both :-

    Please Login or Register  to view this content.
    I got a little more complicated, but i figured somewhere along the line I was over thinking the problem!

    My stab :-

    Please Login or Register  to view this content.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Calculating Alternating Values

    That's a strange formula. It doesn't sum the elapsed times between start time in odd columns and end times in even columns; what does it do?
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Calculating Alternating Values

    Quote Originally Posted by shg View Post
    That's a strange formula. It doesn't sum the elapsed times between start time in odd columns and end times in even columns; what does it do?
    it totals all the end times and subtracts the total of all the start times giving a total time in 1 formula for a whole week of morning afternoon sessions

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Calculating Alternating Values

    it totals all the end times and subtracts the total of all the start times giving a total time in 1 formula for a whole week of morning afternoon sessions
    I don't think so:
    Please Login or Register  to view this content.
    That's your formula in A3.

  7. #7
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Calculating Alternating Values

    its working fine on my sheet?

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Calculating Alternating Values

    Well, then, you're good to go

  9. #9
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Calculating Alternating Values

    As a side note i did some more experimenting and some testing :-

    Fastest, pain to modify
    Please Login or Register  to view this content.
    Second fastest but gives wrong result if the column gets changed
    Please Login or Register  to view this content.
    Third fastest and best since it uses the minimum of cell references/easiest to maintain
    Please Login or Register  to view this content.


    4th fastest UDF
    Please Login or Register  to view this content.
    5th fastest
    Please Login or Register  to view this content.
    6th Fastest
    Please Login or Register  to view this content.
    7th Fastest
    Please Login or Register  to view this content.
    Slowest
    Please Login or Register  to view this content.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Calculating Alternating Values

    How about

    =SUMPRODUCT(I3:AJ3 * -1 ^ (COLUMN(I3:AJ3) + COLUMN(I3) + 1))

  11. #11
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Calculating Alternating Values

    =ABS(SUMPRODUCT((1-ISODD(COLUMN(J3:AK3))*2)*J3:AK3))

    its the second fastest and has the least references

    yes yours was faster, then I thought why not this:-

    Please Login or Register  to view this content.
    it turns out this is actually faster than the straight addition by 7%?

    and only has 2 sets of cell references!

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating Alternating Values

    shg, I like that method a lot... !

    Traditionally you would see:

    MOD(COLUMN(x),1) = 1/0

    used to determine ODD/EVEN in preference to ISODD & ISEVEN given they require the Analysis ToolPak (not so much an issue in 2007)

    shg's -1^COLUMN is a very elegant approach IMO so kudos shg... one to be stored away...

  13. #13
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Calculating Alternating Values

    Just the timings :-)
    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1