+ Reply to Thread
Results 1 to 8 of 8

Having trouble with my nested formula returning a value error

Hybrid View

  1. #1
    Registered User
    Join Date
    03-15-2023
    Location
    California
    MS-Off Ver
    365
    Posts
    9

    Having trouble with my nested formula returning a value error

    Help! I am having trouble with the below formula returning a #value error. I know nested formulas do this sometimes and I need to figure out how to fix this one. What I am doing is calculating clock times, and for some, I need to subtract one hour if they work more than 12 hours and a half hour when they work less than 12.

    IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)>12),ROUND(MOD(L2-K2,1)*24,2)-1),IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)<12),ROUND(MOD(L2-K2,1)*24,2)-0.5,ROUND(MOD(L2-K2,1)*24,2))

    Any help or suggestions is greatly appreciated!

  2. #2
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Having trouble with my nested formula returning a value error

    Try, remove the first bracket highlighted in RED, and put in the last bracket:
    =IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)>12),ROUND(MOD(L2-K2,1)*24,2)-1),IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)<12),ROUND(MOD(L2-K2,1)*24,2)-0.5,ROUND(MOD(L2-K2,1)*24,2)))

  3. #3
    Registered User
    Join Date
    03-15-2023
    Location
    California
    MS-Off Ver
    365
    Posts
    9

    Re: Having trouble with my nested formula returning a value error

    Quote Originally Posted by josephteh View Post
    Try, remove the first bracket highlighted in RED, and put in the last bracket:
    =IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)>12),ROUND(MOD(L2-K2,1)*24,2)-1),IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)<12),ROUND(MOD(L2-K2,1)*24,2)-0.5,ROUND(MOD(L2-K2,1)*24,2)))
    This worked, thank you!!

    Thank you to all who chimed in to help!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,921

    Re: Having trouble with my nested formula returning a value error

    It's going to be difficult to help you if we don't have the data. I am trying to reverse engineer what you are trying to do and it's going to be hard if I have no idea what is in O2, why you care if it is "yes", and also what's in AF2 and why you care if it's 1.

    I am guessing that you just have a syntax error in your nesting. Here is my best guess at fixing your syntax, and it works when I make up some fake data:

    =IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)>12),ROUND(MOD(L2-K2,1)*24,2)-1,IF(AND(O2="yes",AF2=1,ROUND(MOD(L2-K2,1)*24,2)<12),ROUND(MOD(L2-K2,1)*24,2)-0.5,ROUND(MOD(L2-K2,1)*24,2)))
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,353

    Re: Having trouble with my nested formula returning a value error

    Guess this is calculating how long a break to deduct from paid hours. Couldn't work out where it was going wrong so I started from scratch:

    Formula: copy to clipboard
    =LET(oaf,AND(O2="yes",AF2=1),hrs,ROUND(MOD(L2-K2,1)*24,2),IF(AND(oaf,hrs>12),hrs-1,IF(AND(oaf,hrs<12),hrs-0.5,hrs)))


    Josephteh and 6SJ seem to have corrected the problem with the original version.
    Last edited by TMS; 10-23-2024 at 04:31 AM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,921

    Re: Having trouble with my nested formula returning a value error

    TMS solution is overall better because it factors out common logic.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,353

    Re: Having trouble with my nested formula returning a value error

    You're welcome.


    Note that post #4 removes all the repetitive logic.



    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,353

    Re: Having trouble with my nested formula returning a value error

    Thanks for the rep.

+ 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] Trouble with nested IF formula
    By 1993e in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-08-2018, 06:53 PM
  2. Trouble With a Text String Returning Value Error
    By Whard42 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2015, 03:52 PM
  3. trouble with 'cells.find' returning error
    By lbesley in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-20-2014, 09:08 PM
  4. My nested formula is returning a #VALUE! error, and I'm not sure why.
    By zastoic in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-27-2013, 03:19 PM
  5. [SOLVED] Trouble with Find Error Checking: Is Nothing and Is Not Nothing returning the same results
    By k64 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2013, 09:02 PM
  6. Nested if returning error 1004
    By tom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2006, 04:55 PM
  7. Trouble with nested IF formula
    By TheRobsterUK in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-04-2005, 10:05 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