+ Reply to Thread
Results 1 to 8 of 8

VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

  1. #1
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    Hi guys,

    What I'm trying to do is too complex for a regular Excel formula, so I need a VBA. Unfortunately, I know very little about VBA, so I'm really counting on this forum. I think this might be a challenging VBA, but hopefully fun too!

    It's easiest to begin if you look at the attached workbook (My apologies that the formulas are hard to read, they refer to another workbook). As it is now, column CH has a formula that takes the sum of the top three and bottom three values in columns BV:CG. The criteria for "top" and "bottom" is based on the ranks in AX:BH--i.e. if a cell's corresponding "rank" is in the top three highest or lowest in all of the ranks of that row, then that cell is added to the sums in CH. *The formula also only runs if the sums of all corresponding ranks on that row add up to 45* Formula=(IF(SUM($AX4:$BH4)>=45,SUM(SUMIF($AX4:$BH4,LARGE($AX4:$BH4,{1,2,3}),$BV4:$CF4))+SUM(SUMIF($AX4:$BH4,SMALL($AX4:$BH4,{1,2,3}),$BV4:$CF4)),FALSE))

    As it is now, it's wrong.
    First: Instead of using different ranks each day, I need to use the same criteria for the whole work week (5days). In other words, I need to target these parts of the above formula "SUMIF($AX4:$BH4,LARGE($AX4:$BH4,{1,2,3}),$BV4:$CF4)" and "SUMIF($AX4:$BH4,SMALL($AX4:$BH4,{1,2,3}),$BV4:$CF4)" and change them so that the large{1,2,3} and small {1,2,3} of $AX4:$BH4 hold for BV4:CF8, i.e. the whole week.
    Second: The criteria on the last day of the proceeding loop is the criteria for the first day of the next loop. In other words, thought about in a real life scenario, one can only make a decision for that week based on the criteria of the day before.
    Third: If the loop hits a "FALSE" statement (which would happen if the sum of the ranks is less than 45), I need excel to take the next available criteria, and apply that to the next 5 days.
    Fourth: This (above statement) means that the loop needs to be linked to a calender. I can't just apply the same criteria to 5 cells, the next criteria to the next 5 cells, ect, because on the FALSE days, there would not be a sum, but instead the sum would pick back up at the next available criteria, and THEN apply that to the next 5 cells.


    Even a partial code or input would be helpful. I'm really running on nothing.
    Attached Files Attached Files
    Last edited by mkeys4; 07-17-2013 at 11:46 AM.

  2. #2
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    I've fixed the issue, yet I'm still getting reports of people not being able to post to the forum

  3. #3
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    Here's a code I was given, but is flawed. It is populating every other cell. What I need is for the criteria of the previous cell to hold for 5 days, and do this on a loop. But if there's no criteria (i.e. less than 45) for the previous cell, I need excel to find the next possible criteria and apply that to the next 5 days, starting on the next day (just like the first loop).

    There should be no sum on the days when excel tries to pull a criteria and can't find one. And when it does find a criteria, that's when it needs to START the 5 day loop.


    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    Here is the code that solved this issue:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    Glad you solved it - I'll work on someone else's problem.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    I'd like to modify the above code so that the values in "BV:CF" are divided by their corresponding values in "Z:AJ." The cells are consecutive, so BV3/Z3, BW3/AA3, BV4/Z4, ect. I'd like for this to be reflected in the end sum in column CH. Help??
    Last edited by mkeys4; 07-24-2013 at 09:02 AM.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    I'd like to modify the above code so that the values in "BV:CF" are divided by their corresponding values in "Z:AJ." The cells are consecutive, so BV3*Z3, BW3*AA3, BV4*Z4, ect. I'd like for this to be reflected in the end sum in column CH.
    You're saying divided but you're writing multiplied??

  8. #8
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: VBA Code that Sums on a Loop Based on Criteria and Linked to Calender

    Sorry just fixed it. But the problem is already solved with the following code:

    Please Login or Register  to view this content.

    But, what if I wanted the first value in BV:CF to hold for all five days, and still be divided by the values in Z:AJ? So the result would vary because the values in Z:AJ vary, but Z:AJ is the denominator of the same numerator for all five days. As it is now, the rank ranges are being held constant but being applied to varying BV:CF values. How would I change the above code?

+ 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. VBA Code needed for challenging data
    By SAMEEP in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-28-2013, 01:51 PM
  2. Potentially too many arguments
    By Lion400gs in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-28-2013, 09:32 AM
  3. [SOLVED] Check two cells within a row and potentially hide the row
    By Craig K. in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-10-2012, 02:05 PM
  4. Macro to collect Windows and Vital Computer info
    By binster in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-15-2010, 11:40 PM
  5. Potentially stupid negative percentage question :-) help?
    By tabbytails in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-07-2007, 05:18 PM

Tags for this Thread

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