+ Reply to Thread
Results 1 to 17 of 17

IF Statement getting #NA

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    Kent
    MS-Off Ver
    Excel 2007
    Posts
    25

    IF Statement getting #NA

    Hi

    I need some help please.

    The below formula used to work until I added a formula into cell B9 and now I get the equivalent of the #NA message when cellB9 is blank. It works perfectly on non blank cells

    =IFERROR(IF(ISTEXT(B9),VLOOKUP(B9,'Project Codes'!$A$4:$B$22,2,FALSE),IF(B9=0,VLOOKUP(G9,'Nominal Codes'!$A$2:$B$68,2,FALSE))),"NO")

    The formula I have used in B9 is =IF(LEFT(G10,2)="WA",LEFT(G10,6),"")

    I need both formulas to work.

    Can anyone help me please?

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF Statement getting #NA

    When the formula in B9 = "" then ISTEXT(B9) = TRUE and executes the 1st VLOOKUP.

    Maybe replace ISTEXT(B9) with:

    COUNTIF(B9,"?*")

    That's almost the same as ISTEXT but it will ignore the formula blank "".
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: IF Statement getting #NA

    Can you attach the book?
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: IF Statement getting #NA

    can you post the sheet? It's much easier to work of a real sheet...
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF Statement getting #NA

    If B9 is
    =IF(LEFT(G10,2)="WA",LEFT(G10,6),"")
    Then
    ISTEXT(B9) will ALWAYS be TRUE.
    Because the LEFT function returns a Text string, even if it looks like a number.
    So B9 can only return "" <- A text string, or LEFT(G10,6) <- Also a Text string

    Perhaps
    =IF(B9<>"",VLOOKUP(......

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF Statement getting #NA

    Quote Originally Posted by Jonmo1 View Post

    Perhaps
    =IF(B9<>"",VLOOKUP(......
    There's also a next level lookup to account for:

    ...,IF(B9=0,VLOOKUP

    If the cell contains 0 then B9<>"" is TRUE and it will execute the wrong lookup.

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: IF Statement getting #NA

    I've mocked this up on a single sheet. Under what circumstances can you get a zero in B9???
    Attached Files Attached Files

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF Statement getting #NA

    Quote Originally Posted by Tony Valko View Post
    ...,IF(B9=0,VLOOKUP
    B9 will never = 0 either.
    Quote Originally Posted by frootloop View Post
    The formula I have used in B9 is =IF(LEFT(G10,2)="WA",LEFT(G10,6),"")
    I think the whole original formula needs to be reconstructed.

    What results do you want (OP) based on what possible results of the formula in B9 ?

  9. #9
    Registered User
    Join Date
    12-06-2012
    Location
    Kent
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: IF Statement getting #NA

    expenses proforma.xlsx


    Hi Hopefully I have attached the sheet


  10. #10
    Registered User
    Join Date
    12-06-2012
    Location
    Kent
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: IF Statement getting #NA

    Hopefully the sheet above will make it clear. Column b is looking for the first 6 letters in column g but only if they start WA, otherwise I want the cell to remain blank.
    Column F is looking up the nominal code (accounts) from two separate lists dependant on whether there is an entry in column B

    There that sounds so simple doesn't it!

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF Statement getting #NA

    Try this in F8 on the Expenses sheet.

    =IFERROR(IFERROR(VLOOKUP(B8,'Project Codes'!$A$4:$B$22,2,FALSE),VLOOKUP(G8,'Nominal Codes'!$A$2:$B$68,2,FALSE)),"No")

  12. #12
    Registered User
    Join Date
    12-06-2012
    Location
    Kent
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: IF Statement getting #NA

    Jonmo1 you're a genius :D

    That works Perfectly Thank you so much


  13. #13
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF Statement getting #NA

    You're welcome.

  14. #14
    Registered User
    Join Date
    12-06-2012
    Location
    Kent
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: IF Statement getting #NA

    How do I mark this as solved

  15. #15
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF Statement getting #NA

    Quote Originally Posted by frootloop View Post
    How do I mark this as solved
    Select Thread Tools from the menu link above and mark this thread as SOLVED.

  16. #16
    Registered User
    Join Date
    12-06-2012
    Location
    Kent
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: IF Statement getting #NA

    Thank you again

  17. #17
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF Statement getting #NA

    Quote Originally Posted by Jonmo1 View Post
    B9 will never = 0 either.
    Yeah, I should have caught that.

+ 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. 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
  2. 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
  3. Replies: 4
    Last Post: 06-01-2012, 10:05 AM
  4. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  5. [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