+ Reply to Thread
Results 1 to 10 of 10

Macro to limit total sum over multiple rows

  1. #1
    Registered User
    Join Date
    12-11-2019
    Location
    London, England
    MS-Off Ver
    excel office 365
    Posts
    5

    Macro to limit total sum over multiple rows

    Hi All,

    I hope everyone is having a good run up to Christmas!

    I would like to create a script to replicate the steps below so that it does not take me the 3-4 hours it currently does each week to figure out how many hours everyone has actually completed. This is all part of a weekly financial tracker I manage. In the attached spreadsheet I have multiple rows for bookings by individuals in my team.

    What I need to do is limit the total sum of bookings per week to 40 hours as anything beyond 40 needs a different overtime rate.

    Current process:

    1. I sum each row
    2. For any row over 40:
    - I reduce the total value per person per week to 40 by creating a new negative entry (HIGHLIGHTED IN YELLOW)
    - Negative entry is a null row (copying a persons name and the end of week date) with a negative quantity value that equates the total sum to 40.
    3. I separately record how many hours over 40 a person has completed.

    Any ideas, suggestions or working macros would be very much appreciated.

    Thank you all and merry Christmas!
    Attached Files Attached Files

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro to limit total sum over multiple rows

    Isn't it still too early for Christmas ? (even Ali hasn't changing her avatar to the one she is wearing Santa's hat)

    -------

    Ok, first you need to remove the rows marked by yellow background (your calculated rows).
    In my attached file, it is become "Sheet2" (your original sheet "Sheet1" is unchanged, so you can compare them later)

    Then run this macro against this "Sheet2" :
    Please Login or Register  to view this content.
    Attached Files Attached Files
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Macro to limit total sum over multiple rows

    Start by removing all the formulas and conditional formatting and then try this macro:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  4. #4
    Registered User
    Join Date
    12-11-2019
    Location
    London, England
    MS-Off Ver
    excel office 365
    Posts
    5

    Re: Macro to limit total sum over multiple rows

    Hi karedog!

    You may just be right but then again is it ever too early for a little cheer?


    I have just trialled this out and it works perfectly! Thank you!!! - I will be spending the next few hours going through the steps and learning.

    If I can be so direct, I have 1 final question. Is there a way to get the macro to change the entries in column A and B for all new rows created?

    E.g. A = "XX" and B = "01" - this would make filtering out my created data that much easier.
    Last edited by j.jama; 12-11-2019 at 12:16 PM.

  5. #5
    Registered User
    Join Date
    12-11-2019
    Location
    London, England
    MS-Off Ver
    excel office 365
    Posts
    5

    Re: Macro to limit total sum over multiple rows

    Hi Mumps1,


    I am getting a "Run-time error '1004': no cells were found, which seems like it is being caused by the step [For Each Rng In Range("G2:G" & LastRow).SpecialCells(xlCellTypeVisible)]


    Thank you for your response!

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Macro to limit total sum over multiple rows

    When I tested the macro on the file you posted, it worked properly without any errors. Are you using the macro on a different file? It sounds like the solution offered by karedog is working for you.

  7. #7
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro to limit total sum over multiple rows

    Hi j.jama, thanks for rep.points given.
    Yes, You probably right, they have already played christmas movies on cinemas.

    As for your question, just add these code lines in red to the existing code :
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    12-11-2019
    Location
    London, England
    MS-Off Ver
    excel office 365
    Posts
    5

    Re: Macro to limit total sum over multiple rows

    Hi Mumps1,

    Yes karedogs, solution works perfectly! I have a minor edit I would love to integrate but even so that's cosmetic.

    I am not too sure why your solution is not working - probably my incompetence but again thank you for all the help!

  9. #9
    Registered User
    Join Date
    12-11-2019
    Location
    London, England
    MS-Off Ver
    excel office 365
    Posts
    5

    Re: Macro to limit total sum over multiple rows

    Brilliant karedog!

    Rest assured there will be many people who will feel the blessings from your kindness.

    I will make sure to come back and give you a reputation for this follow up answer as soon as I spread the cheer to others. Thank you!

  10. #10
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro to limit total sum over multiple rows

    You are welcome j.jama, thanks for the kind words, and don't forget to mark this thread as solved.

    Regards

+ 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] Macro - Copy and Paste Special Values - limit of Rows
    By sammymalta in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-22-2018, 08:29 AM
  2. [SOLVED] Limit Sorting to Multiple Sets of Rows in Same Column
    By newand in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-20-2017, 06:37 PM
  3. Table of Contents Macro, limit the number of rows
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2016, 03:44 PM
  4. Replies: 3
    Last Post: 04-25-2013, 02:55 AM
  5. [SOLVED] Macro to insert blank rows so that the total number of rows with data is equal to 1021
    By nsm1411 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2013, 10:25 AM
  6. Macro to Limit # of Rows Based on value from other sheet
    By dmysliwy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2012, 09:39 AM
  7. Rows Limit in VBA Macro
    By coolzero in forum Excel General
    Replies: 3
    Last Post: 11-02-2010, 09:18 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