+ Reply to Thread
Results 1 to 5 of 5

Logic test for cell value in a certain format?

  1. #1
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Logic test for cell value in a certain format?

    Please see my attached sample file...

    I am trying to come up with a formula that will return "TRUE" if the preceding cell contains a properly formatted part number, and "FALSE" if the cell contains any letters, text, or numbers formatted differently than a proper part number.

    What I mean by a "proper" part number is a number formatted as four digits, then a dash, and then four more digits, i.e. "1010-0023".

    So far, I've managed to get FALSE if any characters other than "1234567890-" are present in cell A2, and true if cell A2 only contains numbers and/or a "-", using this formula in cell B2:

    Please Login or Register  to view this content.
    However, any number in A1 that is not correctly formatted, but only contains numbers and or dashes, also returns TRUE. So, values like the following need to generate a "FALSE", but don't:


    549824

    11384736

    11325-34562

    6-5-4-3-2

    103-0224


    And so on. I'm sure there's a way to do this, hopefully without resorting to scripts and VBA, but I'm open to any option. Please help!

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,336

    Re: Logic test for cell value in a certain format?

    Try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    So, length is 9, hyphen is in position 5, and the cell value is numeric when the hyphen is removed.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Logic test for cell value in a certain format?

    at B2
    =IF(LEN(A2)<>9,FALSE,ISNUMBER(VALUE(LEFT(A2,FIND("-",A2)-1)&MID(A2,FIND("-",A2)+1,LEN(A2)))))
    copy down

  4. #4
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Logic test for cell value in a certain format?

    Both suggestions work perfectly! I went with TMS's method, only because I was able to change the {1,0} at the end to {"YES","NO"} to better suit my full project. But both options are genius!

    Thanks, guys!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,336

    Re: Logic test for cell value in a certain format?

    You're welcome. Thanks for the rep.


    To be fair, I thought you had 0s and 1s. I'd probably go with "yes" and blank, but you can do with it what your heart desires

+ 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: 3
    Last Post: 09-10-2014, 04:07 PM
  2. IF Statement where Logic Test is a cell that contains a Vlookup
    By dcraggs in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-19-2014, 07:04 AM
  3. help with a logic test
    By BAC_ana in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2010, 09:45 AM
  4. Logic Test??
    By WTB in forum Excel General
    Replies: 2
    Last Post: 12-16-2009, 12:27 PM
  5. [SOLVED] Need help on Logic test!!!
    By jbf frylock in forum Excel General
    Replies: 5
    Last Post: 01-09-2006, 05:45 PM
  6. [SOLVED] logic test
    By toolman in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 10-08-2005, 01:05 AM
  7. hpw do I logic test a cell then copy the row to diff. SS
    By Debi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-05-2005, 05:05 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