+ Reply to Thread
Results 1 to 10 of 10

IF, LEFT, MID problem

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    Collierville, Tennessee
    MS-Off Ver
    Excel 2010
    Posts
    27

    IF, LEFT, MID problem

    I've been working on this for a while and cannot get it to work.

    In the attached example, I have cells E5-E35 in which the user can input various codes. The codes consist of one letter and one number (from 1-8), with the letter always appearing first. There can be one or two codes entered per cell. For example, a cell can have "V4" or "V4 P2"

    In E37, I would like to add up the total values for all "V" codes (which can range from V1 to V8). Unfortunately, the "V" code can be the first or second code entered, as this will depend on the users. Thus, the "V" can either be the 1st value or the 4th value (counting the blank between the codes as a value) in the cell.

    I tried the following, but keep getting the #VALUE! error.

    =SUM(IF(LEFT(E$5:E$35,2)="V1",1),IF(LEFT(E$5:E$35,2)="V2",2),IF(LEFT(E$5:E$35,2)="V3",3),IF(LEFT(E$5:E$35,2)="V4",4),IF(LEFT(E$5:E$35,2)="V5",5),IF(LEFT(E$5:E$35,2)="V6",6),IF(LEFT(E$5:E$35,2)="V7",7),(IF(LEFT(E$5:E$35,2)="V8",8))+SUM(IF(MID(E$5:E$35,4,2)="V1",1),IF(MID(E$5:E$35,4,2)="V2",2),IF(MID(E$5:E$35,4,2)="V3",3),IF(MID(E$5:E$35,4,2)="V4",4),IF(MID(E$5:E$35,4,2)="V5",5),IF(MID(E$5:E$35,4,2)="V6",6),IF(MID(E$5:E$35,4,2)="V7",7),IF(MID(E$5:E$35,4,2)="V8",8)))

    Thanks in advance for your help.
    Attached Files Attached Files
    Last edited by ktbb0312; 04-23-2013 at 12:11 PM.

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

    Re: IF, LEFT, MID problem

    Hi ktbb0312,

    Here's what I came up with... it's an array-formula, so make sure to use array-enter (CTRL-SHIFT-ENTER) and not just ENTER... magical curly brackets will appear...

    =SUM(VALUE(IFERROR(MID($E$5:$E$35,SEARCH("V",$E$5:$E$35)+1,1),0)))

    Let me know if this doesn't work...

    Dennis

  3. #3
    Registered User
    Join Date
    04-18-2013
    Location
    Collierville, Tennessee
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: IF, LEFT, MID problem

    That is so much better. Thank you. It was driving me crazy.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: IF, LEFT, MID problem

    See if this does as you need.

    In a spare column, say Column G, in G5, Drag down to G35. Then Sum(G5:G35)
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    If this gives you the correct result, try this CSE Array, confirm with Ctrl+Shift+Enter not just Enter
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The helper column, Column G isn't required.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Registered User
    Join Date
    04-18-2013
    Location
    Collierville, Tennessee
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: IF, LEFT, MID problem

    Thanks, Marcol. That worked as well.

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: IF, LEFT, MID problem

    Just as a note, my suggestion will work with 2003 and earlier.
    IFERROR() is for 2007 and above, if this is not a requirement, go with Dennis ...

  7. #7
    Registered User
    Join Date
    04-18-2013
    Location
    Collierville, Tennessee
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: IF, LEFT, MID problem

    Dennis - This worked well. After thinking about it some, I think it may be better to display a blank when there is an error, rather than a 0. I tried changing the 0 in your formula to "" but that did not work. Clearly, I'm missing something. Any thoughts?

    Keith

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

    Re: IF, LEFT, MID problem

    Hi Keith,

    Instead of adding to the formula, all you need to change is the number formatting.

    Go to one of the cells and check what number formatting is used. Right click, Format Cells, Number... choose Category: Custom

    In Type: change it to 0;;;

    Let me know if this works.

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: IF, LEFT, MID problem

    This is my suggestion for a single formula, using SUMPRODUCT to avoid "array entry"

    =SUMPRODUCT((0&MID(E5:E35,FIND("V",E5:E35&"V")+1,1))+0)
    Audere est facere

  10. #10
    Registered User
    Join Date
    04-18-2013
    Location
    Collierville, Tennessee
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: IF, LEFT, MID problem

    Thanks, Dennis. That is a good trick.

    Thank you daddylonglegs - I'll give it a whirl.

+ 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