+ Reply to Thread
Results 1 to 12 of 12

VBA Sumifs under two conditions

  1. #1
    Registered User
    Join Date
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    VBA Sumifs under two conditions

    I want to create a function that will sum me up for CRD_EKSP_PIER_DC_FIN = "CRD_EKSP_PIER_DC_FIN" CRD_KOR_DC_FIN = "CRD_KOR_DC_FIN" When two conditions are met, where DIFFRENT> 365 and CRD_RWG <1.5 However, my macro shows me a result of 0. Where do I go wrong ?

    Please Login or Register  to view this content.
    cross post : https://www.mrexcel.com/board/thread...tions.1194722/
    https://stackoverflow.com/questions/...35586_70955630
    Attached Files Attached Files

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2405-17628.20102
    Posts
    1,402

    Re: VBA Sumifs under two conditions

    You seem to be getting a bit confused with the logic i think, the below part is counting the instances of "CRD_EKSP_PIER_DC_FIN" that are found in a column with theheader "CRD_EKSP_PIER_DC_FIN"
    Please Login or Register  to view this content.
    I would expect that you would use:
    Please Login or Register  to view this content.
    To find the cell with the correct header value and then use that cell to look in the column for something else like:
    Please Login or Register  to view this content.
    So - Find header column cell - Use this column - Find something in that column

    Hope this helps

  3. #3
    Registered User
    Join Date
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    Re: VBA Sumifs under two conditions

    I need to add up rCol, but when rCol1 is> 1.5 and rCol2> 365 . My code still is wrong ? still not understand
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,669

    Re: VBA Sumifs under two conditions

    IF I understand you correctly this formula will give the required result. Pl see file.

    =SUMPRODUCT(($A$2:$A$24+$A$2:$B$24)*($C$2:$C$24<1.5)*($E$2:$E$24>365))
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  5. #5
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2405-17628.20102
    Posts
    1,402

    Re: VBA Sumifs under two conditions

    If you are following the VBA route then:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    Re: VBA Sumifs under two conditions

    Quote Originally Posted by kvsrinivasamurthy View Post
    IF I understand you correctly this formula will give the required result. Pl see file.

    =SUMPRODUCT(($A$2:$A$24+$A$2:$B$24)*($C$2:$C$24<1.5)*($E$2:$E$24>365))
    but how to do it in vba ?

  7. #7
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2405-17628.20102
    Posts
    1,402

    Re: VBA Sumifs under two conditions

    Or this may be easier to read:
    Please Login or Register  to view this content.
    Last edited by CheeseSandwich; 02-02-2022 at 10:33 AM.

  8. #8
    Registered User
    Join Date
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    Re: VBA Sumifs under two conditions

    Quote Originally Posted by CheeseSandwich View Post
    Or this may be easier to read:
    Please Login or Register  to view this content.
    I don't know why but it still doesn't work
    crd_rwg must be greater than 1, diffrent greater than 365, and should sum the numbers in the column CRD_EKSP_PIER_DC_FIN

  9. #9
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2405-17628.20102
    Posts
    1,402

    Re: VBA Sumifs under two conditions

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    Re: VBA Sumifs under two conditions

    something wrong is in code, missing something

  11. #11
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2405-17628.20102
    Posts
    1,402

    Re: VBA Sumifs under two conditions

    Have a look at the attachment:
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,669

    Re: VBA Sumifs under two conditions

    Macro code
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. [SOLVED] SUMIFS with two conditions
    By excelactuary in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-14-2021, 12:21 PM
  2. Sumifs/Max with many conditions
    By nickmax1 in forum Excel General
    Replies: 35
    Last Post: 07-09-2018, 06:33 AM
  3. nested sumifs after first two if conditions are met
    By Shruder in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-21-2018, 05:30 PM
  4. SUMIFS with AND conditions; between two dates
    By dchubbock in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-08-2016, 06:36 PM
  5. Sumifs multiple conditions
    By ksmith21 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-16-2015, 06:12 AM
  6. [SOLVED] SUMIFS with OR conditions
    By morbdetro in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-12-2013, 01:01 PM
  7. SumIfs in VBA with two conditions for one range
    By Ivkosky in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2013, 10:04 AM

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