+ Reply to Thread
Results 1 to 9 of 9

Conditional Formula Help ? (IF, OR, LEN(), etc.)

  1. #1
    Registered User
    Join Date
    09-03-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    24

    Conditional Formula Help ? (IF, OR, LEN(), etc.)

    hello, first post here.

    I'm trying to write a function to format a column of cells depending on a set of conditions.

    The attached spreadsheet will give better examples.

    If Cell A1 is 9 alpha numeric and starts with "S999" then display "ONE", if A1 is 9 alpha numeric but does not start with "S999" then display "TWO"

    OR

    If Cell A1 has less than 9 alpha numeric display "THREE"

    Thx!

    EDIT: I have 2003 AND 2007... thx!
    Attached Files Attached Files
    Last edited by winstontj; 09-03-2009 at 09:59 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    Put this formula in B3 and copy down:

    =IF(LEN(A3)=9, IF(LEFT(A3)="S999", "ONE", "TWO"), "THREE")
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    edit: Ooops, I think I misread the question. Did not factor in the length of the string, but instead went for distinguish between pure alpha and alphanumeric. Ah well, maybe someone else will need that, so I'll leave it here.

    Hi, welcome to the board.

    It's ugly but it can be done. Generally, Excel does not distinguish between text and alphanumeric. If it contains letters, then to Excel it's text. So we need to check if the text contains the digits 0-9. The formula below uses the SEARCH function for that. Unfortunately, SEARCH (and FIND as well) return #VALUE when the search item is not found, so we need to embed it into an IF statement to convert the #VALUE to a zero and a successful find into a 1.

    We add up the results for all the searches for digits 0 - 9. If the sum is 0, it means that the cell is purely alpha, so the formula returns THREE. If the som of the search is a number greater than zero, it means that at least one digit has been found, so the text is alphanumeric. So now we check the four leftmost characters and if they equal S999, return ONE, otherwise, return TWO.

    Here is the beast:

    Please Login or Register  to view this content.
    put into cell B3 and copy down.

    enjoy
    Last edited by teylyn; 09-03-2009 at 06:52 PM.

  4. #4
    Registered User
    Join Date
    09-03-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    Quote Originally Posted by JBeaucaire View Post
    Put this formula in B3 and copy down:

    =IF(LEN(A3)=9, IF(LEFT(A3)="S999", "ONE", "TWO"), "THREE")
    too much time staring at this today. Thank you very much. I'm using a formula with four IF(LEN()) statements in a row and totally forgot about the last part of the statement because I was so caught up with my 4 "IF's".

    Thanks again, sorry to waste a post here. I really appreciate the help.

  5. #5
    Registered User
    Join Date
    09-03-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    Quote Originally Posted by teylyn View Post
    edit: Ooops, I think I misread the question. Did not factor in the length of the string, but instead went for distinguish between pure alpha and alphanumeric. Ah well, maybe someone else will need that, so I'll leave it here.
    Thanks for the reply, I just simply allowed my brain to shut down and I forgot about the FALSE portion because I was too caught up with the IF's. Going to take a walk and come back to it.

    Thx again.

  6. #6
    Registered User
    Join Date
    09-03-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    It's not displaying "ONE" and I think I meet all the conditions in the attached sheet.

    Any thoughts?

    EDIT: this is where I was/am stuck:

    =IF(LEN(A3)=9, IF(LEFT(A3)="S999", "ONE", "TWO"), "THREE") this will only display "TWO" and "THREE" but not "ONE"

    which leads me to believe that because the cells that contain "S999" are all also 9-digit alpha numerics it defaults to "TWO"? (or I don't fully understand IF,OR,LEN() functions...

    Thx for any input or thoughts. Very much appreciated.
    Attached Files Attached Files
    Last edited by winstontj; 09-03-2009 at 09:02 PM.

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    I thought the LEFT() function in the formula looked a bit odd. Try this

    =IF(LEN(A3)=9, IF(LEFT(A3,4)="S999", "ONE", "TWO"), "THREE")

  8. #8
    Registered User
    Join Date
    09-03-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    Kiwis coming through for me! Thx that was exactly my problem.

    Just left Auckland not too long ago : (

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Conditional Formula Help ? (IF, OR, LEN(), etc.)

    (*ashamed*) Sorry about that. Noob mistake on my part.

+ 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