+ Reply to Thread
Results 1 to 4 of 4

Nested If statements based on a true condition.

  1. #1
    Registered User
    Join Date
    07-18-2013
    Location
    Cincinnati
    MS-Off Ver
    2010
    Posts
    35

    Nested If statements based on a true condition.

    Can Excel do nested IF Statements if something is true, and something else if the first IF statement is false?

    For instance, in plain english,

    If the cell contains "(" Then have it display as "X" if Cell contains ", ", or as "Y" if Cell Contains "," (no space)
    If cell doesn't contain "(" Then have it display as "Z"

    For instance Lets say A1 contains either "Jones, Rick S (NonEmp)" , "Jones,Rick S (NonEmp), or as "Jones, Rick S"
    Then:
    X = Rick S Jones (NonEmp)
    Y = Rick S Jones (NonEmp)
    Z = Rick S Jones

    Basically I want to take the Name flip it, remove the comma, and append what is in the parenthesis to the end of the string.

    I started another thread which solved some problems, but it was starting to get confusing, so I figured since this is a somewhat different issue I should start a new thread.

    Here is my code.

    Please Login or Register  to view this content.
    This code works if A1 contains either "Jones, Rick S (NonEmp)" or "Jones, Rick S"

    It will not work with "Jones,Rick S (NonEmp)" or if there is no space between the Middle initial and "(".

    I want it to function like this basically...

    Pseudocode:
    Please Login or Register  to view this content.
    if that is too complicated, I at least want to account for spaces after the comma and no spaces after if possible.

    Also I don't need help with getting it to display properly, only with the IF functions and getting them to process correctly, which allows the functions to know how to alter the string to display it uniformly.

  2. #2
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Nested If statements based on a true condition.

    Hi Jhail,

    Did you see my solution in the other thread? I corrected it show 'NonEmp'. You might have to go the 2nd page of the thread...

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Nested If statements based on a true condition.

    This exactly the basis of how IF() statements work...

    =if(criteria-to-test, what-to-do-if-test=TRUE, what-to-do-if-test=FALSE)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    07-18-2013
    Location
    Cincinnati
    MS-Off Ver
    2010
    Posts
    35

    Re: Nested If statements based on a true condition.

    Quote Originally Posted by FDibbins View Post
    This exactly the basis of how IF() statements work...

    =if(criteria-to-test, what-to-do-if-test=TRUE, what-to-do-if-test=FALSE)
    Okay for instance...

    =TRIM(IF(COUNTIF(A1,"*(*") (Condition = Has Parenthesis, meaning I will have to move that to the end of the name after flipping first and last.)
    ,MID(A1,FIND(", ",A1)+2,LEN(A1)-FIND("(",A1)+1) &" "&LEFT(A1,FIND(",",A1)-1) & RIGHT(A1,LEN(A1)-FIND(" (",A1)+1) (Value if True)
    ,MID(A1&" "&A1, FIND(", ", A1)+1, LEN(A1)) )) (Value if False)

    Now if I want it to have a condition, then another condition, then a do if both are true, a do if only first condition is true, and a do if both are false, is that possible?

    So

    =TRIM(IF(COUNTIF(A1,"*(*"), Condition 1
    IF(COUNTIF(A1,"* ,*"), Condition 2
    MID(A1,FIND(", ",A1)+2,LEN(A1)-FIND("(",A1)+1) &" "&LEFT(A1,FIND(",",A1)-1) & RIGHT(A1,LEN(A1)-FIND(" (",A1)+1), Do if Condition 1 & 2 are true.
    MID(A1,FIND(",",A1)+1,LEN(A1)-FIND("(",A1)+1) &" "&LEFT(A1,FIND(",",A1)-1) & RIGHT(A1,LEN(A1)-FIND(" (",A1)+1), Do if second condition is false
    MID(A1&" "&A1, FIND(",", A1)+1, LEN(A1)) )) do if 1 & 2 are false
    Last edited by Jhail83; 08-15-2013 at 10:34 AM.

+ 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. open a comment to cell range upon true condition then removing comment on false condition
    By ferrum_equitis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2012, 12:55 AM
  2. Help: IF Nested condition based on Date to determine Status
    By shoro in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 01-10-2012, 10:21 AM
  3. Replies: 12
    Last Post: 05-15-2009, 08:38 AM
  4. Replies: 6
    Last Post: 10-31-2008, 11:52 AM
  5. Nested IF function, based on two columns TRUE
    By chevyrulz099 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-11-2005, 06:16 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