+ Reply to Thread
Results 1 to 12 of 12

Automatic subtraction

  1. #1
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Automatic subtraction

    Dear all,

    I'm trying to prepare vehicle mileage report based on each vehicle number and date
    is it possible to have in E a formula to do the subtraction of C based on same month in A ? same applies whenever vehicle number changes in B

    thanks a lot for your usual help
    Last edited by legolas; 09-26-2022 at 03:33 AM.

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Automatic subtraction

    Im a little confused by your example data, rows 1-2 make sense in that the difference between them is calculated, but then why are rows 4-6 the total? what makes that different to calculating the difference as per rows 1-2?
    If someone has helped you then please add to their Reputation

  3. #3
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: Automatic subtraction

    Sorry my mistake it should be C7-C5
    Last edited by AliGW; 09-22-2022 at 09:30 AM. Reason: Please DON'T quote unnecessarily!

  4. #4
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,459

    Re: Automatic subtraction

    I'm confused after seeing the numbers in column E.
    I don't understand what the point is.
    It seems that each value in this column has a different meaning.
    Sometimes a difference, sometimes an addition?

  5. #5
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: Automatic subtraction

    i re attached the correct file. sorry for the mistake

  6. #6
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,459

    Re: Automatic subtraction

    The confusion remains exactly the same.
    I do not understand anything about it.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,091

    Re: Automatic subtraction

    Explain the numbers in column E.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,069

    Re: Automatic subtraction

    A long formula, there must be a better formula than this:
    PHP Code: 
    IF(AND(ROW(A2)=MAX((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)*(ROW($A$2:$A$10))),AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)<>AGGREGATE(15,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)),AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)-AGGREGATE(15,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1),IF(AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)=AGGREGATE(15,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1),AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1),"")) 
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: Automatic subtraction

    Quote Originally Posted by AliGW View Post
    Explain the numbers in column E.
    number in E should be the difference between last and first value of C, based on if B has the same plate number and A has the same month
    I'm trying to do subtraction of kms of each plate number for each month

    I hope it is clear, and thank you all for your help
    Last edited by legolas; 09-23-2022 at 03:28 AM.

  10. #10
    Forum Contributor
    Join Date
    09-19-2007
    Location
    Beirut
    MS-Off Ver
    0365 MSO Version 2109
    Posts
    207

    Re: Automatic subtraction

    Quote Originally Posted by josephteh View Post
    A long formula, there must be a better formula than this:
    PHP Code: 
    IF(AND(ROW(A2)=MAX((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)*(ROW($A$2:$A$10))),AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)<>AGGREGATE(15,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)),AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)-AGGREGATE(15,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1),IF(AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1)=AGGREGATE(15,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1),AGGREGATE(14,6,$C$2:$C$10/((MONTH($A$2:$A$10)=MONTH(A2))*($B$2:$B$10=B2)),1),"")) 
    Thanks for your effort and time however when i inserted real values, the formula worked well till E39 !
    when i copied all values down in J,K,L,M,O and E i got #NUM!

    how to fix it ? thanks
    Last edited by legolas; 09-23-2022 at 03:29 AM.

  11. #11
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Automatic subtraction

    well attach some real data and people might be able to see what the problem is. How do we know what e39 is referencing

  12. #12
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,240

    Re: Automatic subtraction

    set g2=1

    in G3

    =IF(AND(MONTH(A3)=MONTH(A2),YEAR(A3)=YEAR(A2)),G2,G2+1)

    copy down

    in F3

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. automatic subtraction
    By legolas in forum Excel General
    Replies: 1
    Last Post: 09-08-2021, 05:21 AM
  2. subtraction with different way
    By Hasson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2021, 11:56 PM
  3. Range Subtraction / Matrix Subtraction - Large data set
    By excelrabbit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2015, 07:07 AM
  4. Automatic Subtraction on xl2007
    By cozzielex in forum Excel General
    Replies: 4
    Last Post: 11-29-2010, 07:31 AM
  5. subtraction
    By Kmac in forum Excel General
    Replies: 2
    Last Post: 04-06-2010, 05:53 PM
  6. Subtraction
    By georgei in forum Excel General
    Replies: 7
    Last Post: 11-04-2009, 10:52 AM
  7. Automatic adding and subtraction entire rows
    By endlyss in forum Excel General
    Replies: 15
    Last Post: 01-23-2009, 09:21 PM

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