+ Reply to Thread
Results 1 to 14 of 14

Limit cell value

  1. #1
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Limit cell value

    I'm working on a spreadsheet that monitors overtime and doubletime. The formulas are correct and working, but it skews the numbers if the subject has more than 8 hours a day or more than 12 hours a day. Let me demonstrate (example)

    A1=regular hours
    A2=overtime hours
    A3=doubletime hours

    A1 has to equal 8 -- even if the subject worked more than 8 hours, I need the difference to go to A2. And again, if the subject worked more than 12 hours, I need the difference to go to A3. I was thinking of using conditional formatting, but I don't know how to create a macro for this. It may not even be possible. I was thinking that if I just state that the subject worked 14 hours for the day, that I could put that in a field and then have it broken down in the other fields, but again, beyond my expertise.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value...kinda

    Oh - and my formula looks like this:

    =IF(AA5>12;AA5-12;0)

    This one calculates doubletime.

  3. #3
    Registered User
    Join Date
    11-09-2007
    Posts
    42

    Re: Limit cell value...kinda

    Maybe you could make a UDF? I always make UDFs when formulas become complex.

    Just change the vHours to the total hours worked and vPayRate to hourly wages. If necessary more variable could be added to determine the cutoff for overtime and double time, but I assumed time up to 8 hours as standard, between 8 and 16 as overtime, and over 16 as doubletime.

    Please Login or Register  to view this content.
    Last edited by Uziel; 04-19-2010 at 11:16 PM.

  4. #4
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value...kinda

    It's a little over my head. I understand what you're doing, but I don't understand how to limit the hours entered in each field.

  5. #5
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value...kinda

    Reading up on it, I believe I need to incorporate the MIN/MAX function, but I just don't know how.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Limit cell value

    If B1 contains a start time, and B2 contains an end time, then

    Reg: =MIN("8:00", B2 - B1 + (B2<B1))

    OT: =MIN("4:00", MAX(0, B2 - B1 + (B2<B1) - "8:00"))

    DT: =MAX(0, B2 - B1 + (B2<B1) - "12:00")

    The formulas assume that you don't work 24 or more hours straight.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value

    The only problem with this is that we don't input our time this way. We have already done the calculation (0900-1730=8hrs). I just want to state that person A worked 13 hours on Monday. Example:

    A1= 13 (total hours)
    A2= 8 (regular hours)
    A3=4 (overtime hours)
    A4=1 (doubletime hour)

    The only field that would be edited would be A1. The calculations would be done from that point forward. (I'll just protect the cells).

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Limit cell value

    Reg: =MIN("8:00", A1)

    OT: =MIN("4:00", MAX(0, A1 - "8:00"))

    DT: =MAX(0, A1 - "12:00")

  9. #9
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value

    Thanks - I'll check it out and reply back.

  10. #10
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value

    I figured it out - thanks to all that replied. I did not use the min/max commands as a surmised that i would.

    Here's the formulas that I used:

    I have an open field that I put the hours worked that day in - From that point it calculates reg time, overtime and dt (there are other fields too, just not important)

    To calc reg time:=IF(AA6>=8;8;+AA6)
    to calc overtime:=IF(AA6>=12;4;AA6-8)
    to calc doubletime"=IF(AA6>12;AA6-12;0)

    Thanks again

  11. #11
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value

    Wait - ****. there's a problem. If the calculated field is a zero, the overtime field will report it as -8. I need it to be zero.

    Can anyone help?

  12. #12
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Limit cell value

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  13. #13
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value

    I deleted the unimportant empty fields to shrink the doc down a bit.

    But here it is,

    thanks.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    04-19-2010
    Location
    socal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Limit cell value

    Got it.

    Here it is:

    =IF(AA6=0;"0";IF(AA6>=12;"4";IF(AA6<12;AA6-8;"0")))

    I needed to nest the IF functions. All good now.

+ 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