+ Reply to Thread
Results 1 to 12 of 12

If/And and Wildcards

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    38

    If/And and Wildcards

    Help!

    I'm trying to create a formula so that if the S&P rating contains "A1" AND the Moody's rating contains "P1", then "High grade" would be returned; if it contains "A2" AND contains "P2", then "Medium grade" is returned, otherwise return "N/A". Can someone help? I need to use wildcards because the rating could be A1, A1+ or A1- so I wanted to use wildcards to pick up anything with "A1".

    S&P Rating Moody's Rating Rating
    A1+ P1

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: If/And and Wildcards

    Perhaps
    Please Login or Register  to view this content.

  3. #3
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: If/And and Wildcards

    Assuming S&P is in A1 and Moody's is in B1:

    =IF(AND(LEFT(A1,2)="A1",LEFT(B1,2)="P1"),"HighGrade",IF(AND(LEFT(A1,2)="A2",LEFT(B1,2)="P2"),"Medium Grade","N/A"))
    Gary's Student

  4. #4
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: If/And and Wildcards

    Assuming A1 is the S&P Rating and B1 is the Moody Rating

    =IF(AND(LEFT(A1,2)="A1",B1="P1"),"High grade",IF(AND(LEFT(A1,2)="A1",B1="P2"),"Medium grade","N/A"))
    Click on star (*) below if this helps

  5. #5
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: If/And and Wildcards

    Rather than wildcards I would use LEFT if the first two positions are the only ones of interest.

    If cell A3 contains A1+ and B3 contains P1- then
    C3=LEFT(A3,2) & LEFT(B3,2)
    D3=if (C3="A1P1", "High grade", if (C3="A2P2","Medium grade", "N/A"))

    You could use LEFT(A3,2)&LEFT(B3,2) instead of using C3 in the D3 formula to reduce the number of cells, though making D3 more difficult to follow.

    Using "AND" instead of concatenations like "A1P1" might be even easier to follow too.
    Chip, if you can read this, you're STILL making the world a better place with your immeasurably valuable gifts. Every week, you continue to help me (and untold numbers of others) tremendously. Practically no alternative outlets can match your effectiveness, even over the vast number of topics you demystify and empower usage of. You were, and still are, amazing.

  6. #6
    Registered User
    Join Date
    10-04-2012
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: If/And and Wildcards

    Hi Pepe, thanks for the suggestion, I've spent hours trying to figure this out! This does the trick except if the ratings are split (for instance A1 and P2), it returns N/A. Is there a way to get it to return a value based on the lower rating, so in this case "Medium Grade"? I attached the workbook using your formula.

    Thanks again!!
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-04-2012
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: If/And and Wildcards

    Quote Originally Posted by Jakobshavn View Post
    Assuming S&P is in A1 and Moody's is in B1:

    =IF(AND(LEFT(A1,2)="A1",LEFT(B1,2)="P1"),"HighGrade",IF(AND(LEFT(A1,2)="A2",LEFT(B1,2)="P2"),"Medium Grade","N/A"))
    Thanks! this looks like another alternative that works except for the issue I posted to Pepe about if the ratings are split (S&P A1, Moody's P2) is there a way to return the lower value (in this case "Medium Grade") instead of returning N/A?

  8. #8
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: If/And and Wildcards

    =IF(AND(LEFT(A1,2)="A1",B1="P1"),"High grade",IF(OR(AND(LEFT(A1,2)="A1",B1="P2"),AND(LEFT(A1,2)="A2",B1="P2")),"Medium grade","N/A"))

  9. #9
    Registered User
    Join Date
    10-04-2012
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: If/And and Wildcards

    Book2.xlsx
    Quote Originally Posted by K m View Post
    =IF(AND(LEFT(A1,2)="A1",B1="P1"),"High grade",IF(OR(AND(LEFT(A1,2)="A1",B1="P2"),AND(LEFT(A1,2)="A2",B1="P2")),"Medium grade","N/A"))
    Hi K m, thanks for helping me with this! This is working for split A1,P2, but not for split A2,P1. Also for A1/P1- it comes up as N/A (which I think has to do with part of the original IF(AND) statement. I tried following your method to correct it, but am getting a formula error and can't figure out where it's from. I attached the workbook with the formula I was trying, can you take a look?

  10. #10
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: If/And and Wildcards

    You did not state the problem correctly the first time. You did not indicate that P1 or P2 could also have a + or - after it, ie P1- or P1+

    Try this for cell C16:

    =IF(AND(LEFT(A16,2)="A1",LEFT(B16,2)="P1"),"High grade",IF(OR(AND(LEFT(A16,2)="A1",LEFT(B16,2)="P2"),AND(LEFT(A16,2)="A2",LEFT(B16,2)="P2")),"Medium grade","N/A"))


    A1 and P1 returns a "High grade"
    Last edited by K m; 10-05-2012 at 10:30 AM.

  11. #11
    Registered User
    Join Date
    10-04-2012
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: If/And and Wildcards

    Quote Originally Posted by K m View Post
    You did not state the problem correctly the first time. You did not indicate that P1 or P2 could also have a + or - after it, ie P1- or P1+

    Try this for cell C16:

    =IF(AND(LEFT(A16,2)="A1",LEFT(B16,2)="P1"),"High grade",IF(OR(AND(LEFT(A16,2)="A1",LEFT(B16,2)="P2"),AND(LEFT(A16,2)="A2",LEFT(B16,2)="P2")),"Medium grade","N/A"))


    A1 and P1 returns a "High grade"
    I apologize if I wasn't clear earlier, the various combos were the reason I thought I had to use wildcards...in any case I made a slight tweak to your proposed formula b/c it still wasn't picking up split A2/P1 combinations that should result in Medium Grade and now it works perfectly! Thanks so much for your help. Here was the final formula:

    =IF(AND(LEFT(A26,2)="A1",LEFT(B26,2)="P1"),"High grade",IF(OR(AND(LEFT(A26,2)="A1",LEFT(B26,2)="P2"),OR(AND(LEFT(A26,2)="A2",LEFT(B26,2)="P1"),AND(LEFT(A26,2)="A2",LEFT(B26,2)="P2"))),"Medium grade","N/A"))

  12. #12
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: If/And and Wildcards

    Be sure to mark as [SOLVED] and click on the star at the bottom of this post

+ 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