+ Reply to Thread
Results 1 to 11 of 11

Loop sumif VBA

  1. #1
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Loop sumif VBA

    hi guys, i have the below code for sumif function

    however, is there a cleaner way to loop this through to the last filled cell in column A instead of listing many lines like below? Thanks.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,174

    Re: Loop sumif VBA

    no need for a loop.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Loop sumif VBA

    Hi Andy, that works perfectly but then i just notice that my sumif function only return the first number of the criteria rather than returning the sum of the total range in sheets("FRUIT").range("L:L"). can you see if my sumif is wrong?

    basically my data is in sheet Fruit between column A to AD and the criteria is in sheet Data2, column A, the column im trying to sum up is sheet Fruit column L, am i missing something here? Thanks.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,174

    Re: Loop sumif VBA

    You need to post example workbook. Include the actual formula you are trying to do via code so we can see expected formula and result.

  5. #5
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Loop sumif VBA

    Sure, i have amended my code and try to incorporate into the one you did but didnt work, my code below, tx

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,174

    Re: Loop sumif VBA

    Can you not post a example workbook?

  7. #7
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Loop sumif VBA

    sure, i have amended my code below

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,174

    Re: Loop sumif VBA

    how does that help with me understand what values are in myrg1 or myrg2 or what the result should be and what it actually is now?

  9. #9
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Loop sumif VBA

    Apols, pls see updated code and attached file, thx

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Loop sumif VBA

    with attachment
    Attached Files Attached Files

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,174

    Re: Loop sumif VBA

    Here is the modified code to replicate your example file.

    Please Login or Register  to view this content.

+ 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