+ Reply to Thread
Results 1 to 5 of 5

Returning an "Error" if specific character is typed into a cell

  1. #1
    Forum Contributor
    Join Date
    02-20-2010
    Location
    Youngstown, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    182

    Returning an "Error" if specific character is typed into a cell

    I have the following formula:

    =IF(ISERROR(LEFT($L22,FIND("'",$L22)-1)+((MID(L22,FIND("'",$L22)+1,LEN($L22)-FIND("'",$L22)-1))/12)), 0, LEFT($L22,FIND("'",$L22)-1)+((MID(L22,FIND("'",$L22)+1,LEN($L22)-FIND("'",$L22)-1))/12))

    This formula looks at a particular cell, in this case cell L22, and takes a value that is shown in FT & fractional inches and converts it to the decimal ft equivalent. Ex: 10' 8 3/8" will return a value of 10.6979. I can then use this value for all my calculations.

    The problem is that some people have a habit of typing the exact same value above but in the following format: 10'-8 3/8". Notice the "-" shown to show seperation from ft and inches. Unfortunately, if this is typed in this format, the formula above will see this as a minus calculation and the value returned is 9.3021 which obviously creates disasterous calculation problems.

    Is there a way to modify the original formula to ignore the "-" character OR if the "-" character is typed in the cell an "ERROR" value will be returned instead?

    Thanks in advance.

    CheddarThief
    Last edited by cheddarthief; 05-26-2011 at 05:17 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Returning an "Error" if specific character is typed into a cell

    =IF(ISNUMBER(SEARCH("-",$L22)),"Do not type minus signs in the cell!!",IF(ISERROR(LEFT($L22,FIND("'",$L22)-1)+((MID(L22,FIND("'",$L22)+1,LEN($L22)-FIND("'",$L22)-1))/12)), 0, LEFT($L22,FIND("'",$L22)-1)+((MID(L22,FIND("'",$L22)+1,LEN($L22)-FIND("'",$L22)-1))/12)))
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    02-20-2010
    Location
    Youngstown, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    182

    Re: Returning an "Error" if specific character is typed into a cell

    romperstomper,
    That worked great. However, after applying it to the spreadsheet, I realize that the cell this formula resides in (P22) is actually in a column that is hidden to the users. It is merely there to perform a calculation so therefore the "Do not type minus signs in the cell" error will not be seen. This made me think, is there a way to put a formula in the actual cell (L22) that in the case where someone 'tries' to type a "-" character in the cell that it returns your error above rather? This will make the error immediately noticable in the actual cell. Is this possible or am I just dreaming?

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Returning an "Error" if specific character is typed into a cell

    You can use Data Validation on that cell, so that if the user types anything with a dash they will get the error...

    While in L22, go to Data|Validation and from the Allow menu select Custom then enter formula:

    =ISERROR(SEARCH("-",L22))

    You can go to the Error Alert tab to customize the message... and you can even go to the Input Message to have a popup message come up to tell them what they should enter
    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.

  5. #5
    Forum Contributor
    Join Date
    02-20-2010
    Location
    Youngstown, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    182

    Re: Returning an "Error" if specific character is typed into a cell

    Guys,
    Both great help. I was able to use both of your ideas to improve my worksheets greatly. Thanks so much for your help.

    CheddarThief

+ 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