+ Reply to Thread
Results 1 to 9 of 9

My nested formula is returning a #VALUE! error, and I'm not sure why.

  1. #1
    Registered User
    Join Date
    11-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    My nested formula is returning a #VALUE! error, and I'm not sure why.

    =IF(AND(RIGHT(J2)="s",SEARCH("-",J2)),LEFT(J2,(LEN(J2)-1)),J2)

    My formula is supposed to check a cell to see if it contains a "-", then also check if it has a "s" at the end. If it meets both conditions, it should remove the "s". This part works.

    The issue is if the cell does not contain a "-" at all. If the formula is used on a cell without a "-", it returns a #VALUE! error. Ideally, the formula should completely ignore the cell and just spit out the cell in its entirety, unedited. I can't quite figure out how to solve this after a lot of Googling.

    Any help is appreciated.

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    It would be helpful if you could post a few examples and tell us what result(s) you expect.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    This is because the Search function returns #VALUE! Error if the string doesn't contain the searched value "-"

    You have to test if the result of search is valid or error.

    Try
    =IF(AND(RIGHT(J2)="s",ISNUMBER(SEARCH("-",J2))),LEFT(J2,(LEN(J2)-1)),J2)

  4. #4
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    try:
    =IF(AND(RIGHT(J2)="s",ISNUMBER(SEARCH("-",J2))),LEFT(J2,(LEN(J2)-1)),J2)
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  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
    44,447

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    One way is to use SUBSTITUTE to replace "-" with "". Compare the LEN before and after. If they are the same, there's no "-", if they're not, there is. Use that instead of SEARCH.

    Regards, TMS
    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
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    Here's my best GUESS...

    Data Range
    J
    K
    2
    xxx-s
    xxx-
    3
    xx-xx-s
    xx-xx-
    4
    xxxs
    5
    ssd-

    Entered in K2 and copied down:

    =IF(COUNTIF(J2,"*-*s"),LEFT(J2,LEN(J2)-1),"")

  7. #7
    Registered User
    Join Date
    11-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    =IF(AND(RIGHT(J2)="s",ISNUMBER(SEARCH("-",J2))),LEFT(J2,(LEN(J2)-1)),J2)

    seems to work. Thank you everyone!

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    You're welcome.

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: My nested formula is returning a #VALUE! error, and I'm not sure why.

    Quote Originally Posted by zastoic View Post
    =IF(AND(RIGHT(J2)="s",ISNUMBER(SEARCH("-",J2))),LEFT(J2,(LEN(J2)-1)),J2)

    seems to work.
    This seems to do the same thing and is a couple of keystrokes shorter:

    =IF(COUNTIF(J2,"*-*s"),LEFT(J2,LEN(J2)-1),J2)

+ 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] Nested IF statements are returning FALSE values - cannot find error in code!
    By apex_chio in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-03-2013, 11:01 PM
  2. Linked Nested IF formula returning 0 and not blank
    By the3rdman77 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-25-2012, 06:30 AM
  3. Formula returning a Value Error
    By Bailey031285 in forum Excel General
    Replies: 5
    Last Post: 09-16-2011, 11:22 PM
  4. formula returning value error
    By keith6292 in forum Excel General
    Replies: 4
    Last Post: 03-12-2010, 06:35 PM
  5. Nested if returning error 1004
    By tom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2006, 04:55 PM

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