+ Reply to Thread
Results 1 to 8 of 8

Shorter or better write CF formula

  1. #1
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Shorter or better write CF formula

    After much toil, I have a working Conditional Formatting formula. This formula takes only the end (anything after the 2nd dash) of a numeric/text string, and evaluates it for the following:

    • Is the end portion after the 2nd dash ("-") a number?
    • If criteria cell = 5, is the end number exactly 6 digits long?
    • If the criteria cell <> 5, is the end number exactly 5 digits long?


    My first formula is in column E of the attachment - but I realized, at least I think, I could safely remove the SUBSTITUTE function, so I have it down to the formula in column F. The formula I currently have is:

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

    My question is, is there either a way to shorten this formula - or - re-write it with the same results?

    The attachment list the expected result and if FALSE, the reason why.

    Sample 5.xlsx




    ...FYI, I have another working formula which evaluates the first and middle parts of the string, including the dashes. For the curious, I put that in column J, and the formula is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ...I can use the 2 formulas separately but would like to combine if possible; however, as written, combining goes over the 255 limit by < 20 characters. Also, FYI, VBA cannot be used for this project.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Shorter or better write CF formula

    formula1
    =AND(ISNUMBER(--MID(B2,FIND("-",B2,4)+1,21)),LEN(MID(B2,FIND("-",B2,4)+1,21))=6-A2<>5)

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: Shorter or better write CF formula

    You can break out the first portion in another CF and add =FALSE
    =ISNUMBER(VALUE(RIGHT(B4,LEN(B4)-FIND("-",B4,4))))=FALSE

    For that CF don't apply any formatting and Check off, "Stop if True".
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Shorter or better write CF formula

    @tim201110 The first portion works great and shortens the existing formula by 11 characters! Question, why you choose "21" as a number of characters for the MID statement? Arbitrary? Also, the end portion, doesn't work out ... not sure if you understood the Criteria Number is just an indicator for determining if the length should be 6 or 5 digits - that actual value in the criteria number field is meaningless. But thanks!

  5. #5
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Shorter or better write CF formula

    try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

    but I think this is too long formula

    but I'd like to know how many (always) characters is after second dash
    Last edited by sandy666; 05-19-2017 at 02:54 PM.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Shorter or better write CF formula

    Quote Originally Posted by CK76 View Post
    You can break out the first portion in another CF and add =FALSE
    =ISNUMBER(VALUE(RIGHT(B4,LEN(B4)-FIND("-",B4,4))))=FALSE

    For that CF don't apply any formatting and Check off, "Stop if True".
    CF only works on TRUE or FALSE, so you dont need the =FALSE at the end, just format as what the rest of the cells would look like
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Shorter or better write CF formula

    21 because i was lucky in Caesars.
    You can use any greater than 6
    this way is better
    =AND(ISNUMBER(--MID(B2,FIND("-",B2,4)+1,21)),LEN(MID(B2,FIND("-",B2,4)+1,21))=6-(A2<>5))

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: Shorter or better write CF formula

    CF only works on TRUE or FALSE, so you dont need the =FALSE at the end, just format as what the rest of the cells would look like
    Oh I just did that to reverse TRUE/FALSE direction. Since I used "Stop if True" to serve as way to break out AND().

+ 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. [SOLVED] how to make a code shorter to write a paragraph
    By eddyrcabrera79 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2015, 01:10 PM
  2. Make this formula shorter
    By Challebjoern in forum Excel General
    Replies: 16
    Last Post: 10-15-2015, 01:28 AM
  3. Make a formula shorter
    By PatrikIden in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-03-2014, 01:45 PM
  4. Shorter formula
    By fivermsg in forum Excel General
    Replies: 3
    Last Post: 01-03-2008, 04:55 PM
  5. [SOLVED] Need faster/shorter formula
    By Luke in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-10-2005, 12:15 PM
  6. [SOLVED] Shorter Formula
    By Pete in forum Excel General
    Replies: 2
    Last Post: 02-18-2005, 12:06 PM
  7. shorter version of formula
    By spirodem in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-31-2005, 09:22 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