Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Sep 2010
    Location
    Cheltenham, Gloucestershire, UK
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts

    LEN not working with IF in Excel 2007!

    I have a spreadsheet where I am trying to use the Len funciton embedded in an If statement and it does not appear to work! What am I doing wrong!

    String len len with If
    W12345 6 A
    123456 6 A
    1234567 7 A
    12345 5 A

    String len len with If
    W12345 =LEN(A2) =IF(A2>6,"A","B")
    123456 =LEN(A3) =IF(A3>6,"A","B")
    1234567 =LEN(A4) =IF(A4>6,"A","B")
    12345 =LEN(A5) =IF(A5>6,"A","B")

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Robert,

    Try this: =If(Len(A2)>6,"A","B") HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    Or
    =If(B2>6,"A","B")

    Steve

  4. #4
    New Lounger
    Join Date
    Sep 2010
    Location
    Cheltenham, Gloucestershire, UK
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Sorry I have made an error in my typing! The formula I was using did include the Len - i.e. =if(len(A2)>6,"A","B")

    The strange thing was that if the length was 6 it gave a result of A rather than B. I did a trim and clean just to be sure there were no hidden characters or unexpected spaces but to no avail!

    12345 b
    123456 b
    1234567 a

    12345 =IF(LEN(A1)>6,"a","b")
    123456 =IF(LEN(A2)>6,"a","b")
    1234567 =IF(LEN(A3)>6,"a","b")

  5. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    I don't get the strange performance. I can match your output with the formulas you list.

    Could you attach a file demonstrating the miscounting or misapplied len?

    Steve

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Robert,

    Like Steve it works fine for me.
    LenTest.JPG

    Here's the test file: LenTest.xlsx HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •