+ Reply to Thread
Results 1 to 5 of 5

Formula to sort cells containing less & more than a number of characters

  1. #1
    Forum Contributor
    Join Date
    08-21-2014
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    232

    Question Formula to sort cells containing less & more than a number of characters

    Hi,

    I have postcode data which I have a VBA code formula to standardise.

    That part is set - but I want a fomula which will look at the data and not run the postcode formula if the cells conatins less than 6 characters or more than 8 characters.

    I currently have this;

    =IF(AND(LEN('Postcodes'!A1)<6,LEN('Postcodes'!A1)>8),"",FormatPostcode('Postcodes'!A1))

    But it returns a #NA rather than a blank if the data is to be excluded.

    What's amiss please?

    Thanks in advance,

    Ian

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,207

    Re: Formula to sort cells containing less & more than a number of characters

    try

    =IF(OR(LEN('Postcodes'!A1)<6,LEN('Postcodes'!A1)>8),"",FormatPostcode('Postcodes'!A1))

  3. #3
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Formula to sort cells containing less & more than a number of characters

    Hi,

    Don't you need "OR" instead of "AND"?
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

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

    Re: Formula to sort cells containing less & more than a number of characters

    Maybe this...

    =IF(OR(LEN('Postcodes'!A1)={6,7,8}),FormatPostcode('Postcodes'!A1),"")
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Forum Contributor
    Join Date
    08-21-2014
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    232

    Re: Formula to sort cells containing less & more than a number of characters

    John's answer looks to have cracked it - let me run over 25k lines of data and will shout if any problems. Thank you all.

+ 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: 02-09-2016, 11:00 AM
  2. [SOLVED] Sort by number and ignore characters.
    By Ataraxicatom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2014, 03:47 PM
  3. Sort by number of characters in cell/column? How please?
    By be-nice-2-me in forum Excel General
    Replies: 3
    Last Post: 06-25-2013, 08:09 AM
  4. sort list/range of number with special characters
    By jscc in forum Excel General
    Replies: 8
    Last Post: 08-03-2012, 04:24 PM
  5. sort list/range of number with special characters
    By jscc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-15-2012, 01:29 PM
  6. Sort by number of characters?
    By DrSues02 in forum Excel General
    Replies: 5
    Last Post: 01-16-2011, 04:21 PM
  7. Is there a way to sort items by the number of characters?
    By jdwilliams1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-19-2006, 12:56 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