+ Reply to Thread
Results 1 to 19 of 19

Adding Multiple Lines when "IF" is True

  1. #1
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80

    Adding Multiple Lines when "IF" is True

    I am having a few problems trying to come up with a function that can satisfy this problem. Sometimes one employee may appear under more than one group (bartender, barback, waitstaff, etc.). I need to insert a formula that will check the other groups to see if this employee worked any hours in another group that week (I would assume a VLOOKUP would work), and then distribute the overtime hours accordingly.

    If you view the attached worksheet, you can see I've entered a name and some hours. The formulas in cells M2 and N2 are my attempt to fix this problem. Anyway, the way the overtime hours are distributed is based on the group they worked under after they reached 40 hours. So looking at the example on the worksheet, Bob should have all of his overtime (13 hours) appear under O/T in row 2 because the 9 hours he worked on the waitstaff was before he was "officially" earning the overtime.

    So I am needing the formula to check all of the groups other than it's own for a duplicate, add the total hours, and distribute the overtime accordingly.

    Thanks in advance for any assistance, if there are any questions I can answer to help you out, feel free to ask.

    Thanks again.
    Attached Files Attached Files
    Last edited by pugsly8422; 08-25-2008 at 10:22 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Perhaps something like this?

    In M2: =IF(ISNUMBER(MATCH(A2,A$17:A$53,0)),A2,"")

    In N2: =MAX(0,SUMIF(A:A,M2,L:L)+SUMIF(A:A,M2,K:K)-40)
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    i'd just insert a new column m which has totals sum(d2:j2)
    for each person
    then use in column N against each name in column A
    =SUMIF($A$1:$A$100,"bob",$M$1:$M$100)-40 gives 13 for bob

  4. #4
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    I appreciate the help from both of you.

    Both of your methods seem to get me through the first step, which is figuring out how much overtime the person, in this case Bob, has worked. I am trying to insert the fuctions into L2 and L22, but am getting a circular reference, is there any way to avoid this? If possible, I'd like to avoid using columns M and N all together, but I can always hide those.

    If Bob happens to work 2 hours on Sunday on the waitstaff, will the formula show those 2 hours of overtime in L22?

    I hope I'm not making this too confusing, I really appreciate all of your assistance.

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    So do you want the actual number 13 to appear? If so, where?

  6. #6
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    Quote Originally Posted by NBVC View Post
    So do you want the actual number 13 to appear? If so, where?
    Yes, I would like 13 to appear in L2 and 0 to appear in L22.

    I added John to the list as well to try and make it easier to understand how the overtime works. Wherever the person is working when anything above 40 hours is earned is where the overtime should go. So in John's case he has 40 hours Mon-Fri as a bartender, so no overtime there. But he worked 10 hours (5 and 5) on the waitstaff after he had reached 40 total hours for the week, so he will be receiving overtime for those 10 hours he worked on the waitstaff, but none for the 40 hours as a bartender. If he had worked 9 hours on Monday then 1 of his hours as a bartender on Friday would have been overtime, as well as all of his hours on the waitstaff.

    Thanks again for helping me out with this, I'm sure you can tell it has been driving me insane!!

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    I didn't see any data for John as you mentioned.

    Also, please resubmit the workbook showing some entries and expected results with explanations on how the results were obtained.

  8. #8
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    Sorry, I failed to attach the new workbook. I've also added Todd to the list.

    Bob - he worked on waitstaff and bartending, once the total hours worked (bartending+waitstaff) reaches 40, everything after that will be overtime and need to go in the L column. Bob had 12 hours Monday, 14 Tuesday, 9 Wednesday, 9 Thursday and 9 Friday for a total of 53 hours. After he reaches 40 hours on Thursday, everything needs to go in the L column, whether he's bartending, a barback, or on the waitstaff.

    John - he reached 40 hours at the end of the day Friday, so any hours he works Saturday or Sunday will be overtime. That means the 5 hours he worked on the waitstaff on Saturday and Sunday will be overtime, 10 hours total.

    Todd - I put his explanation on the workbook.

    Somehow the fuction that goes in L2 will have to know that Bob also worked hours on the waitstaff, and the function in L22 will have to know that he worked hours bartending.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    bob #1 would be his hours bartending, bob #2 would be his hours barbacking, bob #3 would be his hours on the waitstaff, bob #4 would be his hours hosting and bob #5 would be his hours training. I bolded every other part of the function to hopefully make it easier to read.

    I was thinking L2 would be something like:

    if(bobs name appears more than once,if(bob #1 monday hours+bob #2 monday hours+bob #3 monday hours+bob #4 monday hours+bob #5 monday hours>40,bob #1 monday thru sunday hours+bob #2 monday thru sunday hours+bob #3 monday thru sunday hours+bob #4 monday thru sunday hours+bob #5 monday thru sunday hours-40,if(bob #1 monday thru tuesday hours+bob #2 monday thru tuesday hours+bob #3 monday thru tuesday hours+bob #4 monday thru tuesday hours+bob #5 monday thru tuesday hours>40,bob #1 monday thru sunday hours+bob #2 monday thru sunday hours+bob #3 monday thru sunday hours+bob #4 monday thru sunday hours+bob #5 monday thru sunday hours-40,if(bob #1 monday thru wednesday hours+bob #2 monday thru wednesday hours+bob #3 monday thru wednesday hours+bob #4 monday thru wednesday hours+bob #5 monday thru wednesday hours>40,bob #1 monday thru sunday hours+bob #2 monday thru sunday hours+bob #3 monday thru sunday hours+bob #4 monday thru sunday hours+bob #5 monday thru sunday hours-40..........,if(bob #1 monday thru sunday hours+bob #2 monday thru sunday hours+bob #3 monday thru sunday hours+bob #4 monday thru sunday hours+bob #5 monday thru sunday hours>40,bob #1 monday thru sunday hours+bob #2 monday thru sunday hours+bob #3 monday thru sunday hours+bob #4 monday thru sunday hours+bob #5 monday thru sunday hours-40)))))))

    I'm sure that function is impossible to fit in a single cell, so I'm hoping there is an easier way to do it.

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    For now I have used this formula in L2, copied down... which gives the results you have in the Bartender area...

    =IF(A2="","",MAX(0,SUMPRODUCT(($A$2:$A$53=A2)*ISNUMBER($D$2:$H$53),($D$2:$H$53))-40))

    but I am unsure how you get the numbers in column L of the Waitstaff area?

  11. #11
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    Thanks again for your help. The numbers in column L of the waitstaff area are determined the say as the ones in the bartending area. I got the 10 for John by getting his 40 hours from working monday thru friday bartending, and then him working 5 hours saturday and 5 hours sunday on the waitstaff. If you add up all of Johns hours for the week, he worked 50 total, so he has to have 10 hours of overtime. Those 10 hours will be the last 10 he worked, and the last 10 he worked were on the waitstaff, so that is where that overtime will go.

    Great job with the formula, that seems to work perfectly!

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    I'm gone for the day.. I can look at it again tomorrow...

  13. #13
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    Thank you very much.

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Sorry for not coming back yesterday as promised I was not well and laid in bed all day....

    Anyways, give this formula a try in L2 and copy it down the whole column.... at the points where the headings of the subgroups are you can overwrite the formula with "O/T" subheading...

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    Quote Originally Posted by NBVC View Post
    Sorry for not coming back yesterday as promised I was not well and laid in bed all day....

    Anyways, give this formula a try in L2 and copy it down the whole column.... at the points where the headings of the subgroups are you can overwrite the formula with "O/T" subheading...

    Please Login or Register  to view this content.
    We all get sick, I totally understand. That formula did exactly what I was hoping for. I want to thank you for all of your assistance. Is there a link you can give me where I can make a donation/contribution toward the site?

    Thanks again for your help, that formula was amazing!

  16. #16
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    I'm not sure the site has facilities for accepting contributions... I think it is ad-sponsored. We don't get paid here... we are all volunteers having fun with Excel.

    Thanks for the feedback. Glad the formula worked for you.

  17. #17
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    Actually, there still seems to be a problem with the formula. Originally it wasn't including Saturday or Sunday in the calculation, but I was able to adjust the formula for that. Now what it is doing is putting all of the overtime in one location.

    I think this will be a simple thing to fix, or at least I hope it will.

    L2 should say 9 because 9 hours of overtime were earned bartending, and the other 3 hours should be under L24 for barbacking. It is calculating the correct total amount of overtime, just isn't dividing it out correctly. Sorry to keep bothering you with this.

    I've attached an updated copy of the spreadsheet and included some notes.

    Thanks again.
    Attached Files Attached Files

  18. #18
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    This makes it much more complicated....

    See attached and hopefully it works for you...

    I added some helper columns to determine when the employee passes the 40 hour mark... These columns can be hidden if you wish...

    so the formula for the first helper column would be
    Please Login or Register  to view this content.
    This is copied across 7 columns and down the list....

    Then in L2:
    Please Login or Register  to view this content.
    which is an array formula and must be confirmed with CTRL+SHIFT+ENTER not just ENTER. You will see { } brackets appear around the formula.

    Then you can copy it down.
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    08-25-2008
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    80
    It looks like that worked and it is officially completed. Thanks again NBVC for all of the time and effort you put into this, it is greatly appreciated!

+ 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. Multiple lines in single cell
    By Bill Pearce in forum Excel General
    Replies: 5
    Last Post: 04-02-2015, 10:59 AM
  2. Pasting multiple lines of text into one cell
    By hoopz in forum Excel General
    Replies: 4
    Last Post: 07-11-2012, 08:28 PM
  3. what do I type to specify to import from the folder that I just browsed for?
    By hluk in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-27-2008, 06:46 PM
  4. Speeding Up VBA Programming
    By pickledmuffin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-13-2008, 01:54 AM
  5. Need help shortering my code with a loop
    By Loranga in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-04-2007, 03:06 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