+ Reply to Thread
Results 1 to 21 of 21

If Statement Help

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    If Statement Help

    In range B1:B4 I'll have letters ranging from A to F. So B1 could be E and B2 could be A. These letters will always be unique.

    I need an IF statement (I think) that looks for the letter B in this range and if found, returns whatever is in the cell directly to the left of it. If B is not found, then look at the letter E and if found return the cell directly to the left of it. If neither B or E are found then it should look for the letter F (which will be there somewhere) and return the cell directly to the left of it.

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: If Statement Help

    I think a sample workbook would help but give this a try.
    Please Login or Register  to view this content.
    Last edited by mikeTRON; 05-10-2016 at 10:06 AM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    Thanks Mike but that doesn't work.

    I've uploaded a sample.
    Attached Files Attached Files

  4. #4
    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,946

    Re: If Statement Help

    THis is obviously a very simplistic example, and, with 6 possible letters, could probably be done with index and 6 nested iferror/matches, but I have a feeling you have far more than 6 - which makes that options impractical.

    What exactly are you trying to do here, and can you give a more realistic example?
    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

  5. #5
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: If Statement Help

    Copy and paste into cell A8:
    Please Login or Register  to view this content.
    Then you can copy and paste that into G8, L8 and P8.

  6. #6
    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,946

    Re: If Statement Help

    Mike I was thinking along those same likes (you can just use 1 index, and put the IFERRORS all inside that)


    =INDEX(A$1:A$4,IFERROR(MATCH("B",B$1:B$4,0),IFERROR(MATCH("E",B$1:B$4,0),IFERROR(MATCH("F",B$1:B$4,0)))),"")
    (Think I got teh ) right)

    However, if you start adding more, it will soon become unmanageable (either way)

  7. #7
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: If Statement Help

    Quote Originally Posted by FDibbins View Post
    Mike I was thinking along those same likes (you can just use 1 index, and put the IFERRORS all inside that)


    =INDEX(A$1:A$4,IFERROR(MATCH("B",B$1:B$4,0),IFERROR(MATCH("E",B$1:B$4,0),IFERROR(MATCH("F",B$1:B$4,0)))),"")
    (Think I got teh ) right)

    However, if you start adding more, it will soon become unmanageable (either way)
    Yeah I originally started your method as I personally like it more, but I think someone who is newer will more easily follow the formula I put together... but who knows haha

  8. #8
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    Nope, 4 numbers is as big as it'll get!

    I actually got it working using

    Please Login or Register  to view this content.
    However I need to add something to the code so that if the word the above formula returns already exists in cell A8 then look at the next letter. So if the letter B was found in B1 and A1="Cat" and A8="CAT", then it should look at finding E if it exists in the range and if not look at finding F after that.

  9. #9
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: If Statement Help

    Provide an example workbook that is representative of your problem and we can help otherwise we are just spinning our wheels talking in the forum.

    Provide plenty of test cases to prove the logic works, like your new found CAT exemption.

  10. #10
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    Attached new sample file for you to get an idea of what I'm after. Appreciate the assistance so far.
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    Any help with this or could you not figure it out?

  12. #12
    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,946

    Re: If Statement Help

    Sorry, if anything, that is even more confusing that the 1st sample file

    Did you read my post #4?

  13. #13
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: If Statement Help

    Yeah I read it but I am not sure I follow as well.

    Are you telling me that if CAT exists AT ALL, then it should ALWAYS return cat, otherwise return the name next to B, then E then F?
    Or are you saying if B exists then use it, if B doesnt exist THEN look for CAT and if so then CAT otherwise look for E THEN F?


    EDIT: Actually, yeah your example is completely different than your first example. Make a CLEAR example and explain the logic that needs to happen maybe like the example I gave below.

    1) look for B
    if B appears then give word next to B, if not go to 2)
    2) look for CAT
    3) look for E
    4) look for F

    ETC ETC ETC
    Last edited by mikeTRON; 05-11-2016 at 02:37 PM.

  14. #14
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    1. Look for "B"
    If found then give the word next to B provided A8 does not contain the same word that is next to B, else go to 2

    2. Look for "E"
    If found then give the word next to E provided A8 does not contain the same word that is next to E, else go to 3

    3. Look for "F"
    If found then give the word next to F. A8 will never equal F if the formula gets this far. If not found return "Fail".

  15. #15
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: If Statement Help

    And no CAT stipulation?

  16. #16
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    CAT is just a random word. Whatever is contained left of where B or E or F is found and within cell A8 is what matters. I used CAT as an example of what could be in cell A8 or in the range A1:A4.
    Last edited by ScabbyDog; 05-12-2016 at 10:35 AM.

  17. #17
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: If Statement Help

    This I think is similar to Ford's solution. Enter in A8, and for the other amend the ranges as required. You could fill this across then delete the formulae that are between the ranges that are not needed.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  18. #18
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    Quote Originally Posted by newdoverman View Post
    This I think is similar to Ford's solution. Enter in A8, and for the other amend the ranges as required. You could fill this across then delete the formulae that are between the ranges that are not needed.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If I put that into A9 and drag across it works but it doesn't take into account what is in cell A8 which is the key to this problem.

  19. #19
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: If Statement Help

    In light of your description of the problem at the beginning, A8 has nothing to do with it. When you stated the problem, you gave a specific order for matches to occur but your last statement doesn't make sense when compared to the statement of the problem.

  20. #20
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    Quote Originally Posted by newdoverman View Post
    In light of your description of the problem at the beginning, A8 has nothing to do with it. When you stated the problem, you gave a specific order for matches to occur but your last statement doesn't make sense when compared to the statement of the problem.
    You've solved my problem from the initial post. However, I then subsequently added a condition in that has yet to be solved. Hopefully mikeTron or FDibbins can solve it.

  21. #21
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: If Statement Help

    Managed to solve it myself. Was actually much easier than I thought in the end! Just an IF statement with nested AND's in it! Thanks for the help anyway guys.

+ 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. Replies: 2
    Last Post: 07-09-2015, 04:25 PM
  2. [SOLVED] If statement to select data - nested statement - assistance
    By petitesouris in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-29-2015, 09:55 PM
  3. compile error expected line number statement end statement
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2014, 10:12 AM
  4. VBA Compile Error : line number or label or statement or end of statement
    By excellearner121 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2013, 06:41 PM
  5. Replies: 4
    Last Post: 06-01-2012, 10:05 AM
  6. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  7. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08: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