+ Reply to Thread
Results 1 to 13 of 13

Logical Test on a Substring in a Text

  1. #1
    Registered User
    Join Date
    03-26-2016
    Location
    Salt Lake City, Ut
    MS-Off Ver
    MS Office 2013
    Posts
    8

    Logical Test on a Substring in a Text

    I need a logical test to help me build automatic comments for tracking freight. Below is my example (simplifed)

    Column A Column B
    95D55 32:40-

    This reads "Truck 95D55 is 32hrs 40 minutes ahead". The reason you say this truck is early, or running ahead on this load is the "-" character on the number in column B. If there is a "-" its early. If there is no "-" its running late. I'm having trouble finding a logical test that would return a text value. Ideally it would run something like this using plain English:

    =If(B1 contains the character "-", then return B1 value as the text string "32hrs 40mins ahead",else return B1 as the text string "32hrs 40mins late)

    Any and all help is appreciated. I have trouble spelling and phrase things awkwardly so I try to use formulas and other things to build automatic phrases to track freight. Im always looking to improve on what I got.
    Last edited by MexicoGuy; 03-26-2016 at 10:12 PM. Reason: I suck at spelling

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Logical Test on a Substring in a Text

    Hi and Welcome and happy Easter

    try this

    Please Login or Register  to view this content.
    Happy with my advice? Click on the * reputation button below

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Logical Test on a Substring in a Text

    Using this example:
    A
    B
    C
    1
    Vehicle
    StatusTime
    Status
    2
    95D55
    32:40-

    Try this formula:
    Please Login or Register  to view this content.
    In that example, the formula returns: 32hrs 40mins ahead


    Is that something you can work with?
    Last edited by Ron Coderre; 03-26-2016 at 11:18 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Logical Test on a Substring in a Text

    Or try this...
    =TEXT(--SUBSTITUTE(B2,"-",""),"[h]"" hours ""mm") & IF(RIGHT(B2,1)="-"," mins early"," mins late")
    Last edited by Phuocam; 03-27-2016 at 10:15 AM.

  5. #5
    Registered User
    Join Date
    03-26-2016
    Location
    Salt Lake City, Ut
    MS-Off Ver
    MS Office 2013
    Posts
    8

    Re: Logical Test on a Substring in a Text

    Thank you for your help! All three of you. But it didn't work because of an error of mine in framing the question. My apologies to all. I wanted to simplify the problem, but I am afraid I overly did so. Let me try this again.

    Below in Col A is the full text I have to work with in all its glory, "95D55· A6 0187350 02 SUNY·· SCA BAY L -2AGNOR.06 315 32:40-". Its components are 95D55 = Truck number, A6 = Fleet, 0187350 = Trip number, "SUNY" = Customer, "SCA" = Origin of trip, "BAY" = Destination of same, "L" = Trip is loaded, "-2AGNOR.06" = Various trip conditions of load, "315" = miles left, and "32:40-" = the time running ahead or behind.

    This Order NEVER VARIES. Its the one of the two fixed characteristics in this text string. The second are the spaces between each pieces of information. The report even adds "dot" after some of the text to be sure the structure of spaces stays the same. Both the order of information and structure of the sentence is fixed and doesn't change.

    As already mentioned the "-" indicates if a load is running ahead or on time. The lack of "-" indicates load is late. I guess what I need is more complicated, maybe than I thought. If I had to restate in words the formula or series of combinded functions I need it would sound something like this"

    "if(the last 6 characters of A1 equals contains "-", return "32hrs and 40 min ahead",if the last 6 characters of A1 does not contains "-", return 32hrs 40min late)

    I hope this explains it better.


    Col A
    Col A Col B
    95D55· A6 0187350 02 SUNY·· SCA BAY L -2AGNOR.06 315 32:40-

  6. #6
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Logical Test on a Substring in a Text

    you can use this formula:
    =TEXT(--TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",10)),10)),"[h]"" hours ""mm") & IF(RIGHT(A1,1)="-"," mins early"," mins late")

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Logical Test on a Substring in a Text

    or... =TEXT(--TRIM(RIGHT(A1,6)),"[h]"" hrs ""mm") & IF(RIGHT(A1,1)="-"," mins early"," mins late")

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Logical Test on a Substring in a Text

    You could try something like this:
    Please Login or Register  to view this content.
    (The formatting is a bit cryptic whichever way you go)
    Does that help?

  9. #9
    Registered User
    Join Date
    03-26-2016
    Location
    Salt Lake City, Ut
    MS-Off Ver
    MS Office 2013
    Posts
    8

    Re: Logical Test on a Substring in a Text

    Phucam and Ron,

    Thank you it worked!! Like a champ!! Greatly appreciated. But one small problem came up. You will see in cell B2 that "#VALUE!" came up. This occurred because this load is not assigned a truck at this moment. This is known from both the "NO_DRV" substring and there is no time text.

    Final question (I hope) is there way to modify the formula in B2 so that if it were not assigned it just returns the phrase "Not Tracking" rather than #VALUE!" error??

    If not, I can more than live with it. Thanks again for your help!!


    Col A Col B
    96787 A2 0187360 01 SUNY·· ECR BAY L -3AGNRV.09 235 14:40- =TEXT(--TRIM(RIGHT(A2,6)),"[h]"" hrs ""mm") & IF(RIGHT(A2,1)="-"," mins early"," mins late")
    NO_DRV ·· 0192150 01 SUNY·· ECR BAY K 0 Formula above returns "VALUE!"


    Thanks again for you patience and help.

  10. #10
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Logical Test on a Substring in a Text

    Try one of these:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-26-2016
    Location
    Salt Lake City, Ut
    MS-Off Ver
    MS Office 2013
    Posts
    8

    Re: Logical Test on a Substring in a Text

    Both of the above formulas returned the value "late". At the end of the original text there are 6 spaces that, although show no text, actually exist. One of the things about the computer system we use is that these text strings ALWAYS have the same format and ALWAYS maintain the same structure. So even though there is no time at the end of the text the system maintains 6 spaces for it plus one space to seperate it from the next substring. In this case its "0". Imagine 0 with a space after it and six invisible letters.

    Its one of the frustrating things working with our computer system.

    Did I miss something? Again Thanks for the help!



    Original Text Formula Result
    NO_DRV ·· 0194170 01 SUNY·· ECR BAY K 0 =IFERROR(TEXT(TRIM(RIGHT(A23,6)),"[h]""hrs ""m""min """)&IF(RIGHT(A23,1)="-","ahead","late"),"Not tracking") late

  12. #12
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Logical Test on a Substring in a Text

    Try again:
    =IF(ISNUMBER(--TRIM(RIGHT(A23,6))),TEXT(TRIM(RIGHT(A23,6)),"[h]""hrs ""m""min """)&IF(RIGHT(A23,1)="-","ahead","late"),"Not tracking")

  13. #13
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Logical Test on a Substring in a Text

    or try:
    =IFERROR(TEXT(--TRIM(RIGHT(A23,6)),"[h]""hrs ""m""min """)&IF(RIGHT(A23,1)="-","ahead","late"),"Not tracking")

+ 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. Logical test false values skip to next row for next test
    By Schecter89 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-23-2018, 06:36 AM
  2. [SOLVED] constructing IF logical test based on text string stored in other cell
    By 7344Robin in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-29-2014, 11:27 AM
  3. CREATE A LOGICAL TEST CONTAINING TEXT
    By help needed in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-17-2006, 10:05 AM
  4. [SOLVED] logical test, array, text and numbers
    By Dan M. in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-25-2006, 04:00 AM
  5. [SOLVED] Logical Test if statements with text--Excel 2002
    By Don Guillett in forum Excel General
    Replies: 3
    Last Post: 11-02-2005, 07:35 PM
  6. [SOLVED] Logical Test if statements with text--Excel 2002
    By Matt in forum Excel General
    Replies: 0
    Last Post: 11-02-2005, 06:17 PM
  7. [SOLVED] change text color based on logical test
    By T3nMan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-19-2005, 01:06 PM

Tags for this Thread

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