+ Reply to Thread
Results 1 to 15 of 15

Strange Results From Formula

  1. #1
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    Posts
    172

    Strange Results From Formula

    I am getting strange results from a formula and wonder if anyone could explain as to what is occurring and what I need to do to overcome the issue. I have attached a sample file showing precisely what the issue is and highlighted the problem lines. Thanks
    Attached Files Attached Files

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

    Re: Strange Results From Formula

    It's because of this...

    =MID(B3,SEARCH(LEFT(TRIM(B3),1),B3), SEARCH(RIGHT(TRIM(B3),1),B3) -SEARCH(LEFT(TRIM(B3),1),B3)+1)

    When the data string contains duplicate characters like this...

    \298-T2020

    The highlighted section of the formula finds the leftmost instance of the character...

    \298-T2020
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    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,258

    Re: Strange Results From Formula

    What are trying to do with the formula?

    Looking at the non-highlighted results the =TRIM(B3) would get the same result.

  4. #4
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    Posts
    172

    Re: Strange Results From Formula

    Tony - thanks for the response. That explains what is occurring. Do you have any suggestions as to how I might overcome this?

  5. #5
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Strange Results From Formula

    Hi
    You formula fail because B8 as two "F"

  6. #6
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    Posts
    172

    Re: Strange Results From Formula

    What I am trying to do is to remove the leading and trailing spaces but leave any spaces that occur between the words. If I use =Trim(B3) then all spaces are removed. Cheers

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,247

    Re: Strange Results From Formula

    But there are no spaces between words in your test data! Perhaps you need to provide a more realistic sample?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,791

    Re: Strange Results From Formula

    No, TRIM will remove multiple spaces between words, but will leave a single space instead.

    Pete

  9. #9
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    Posts
    172

    Re: Strange Results From Formula

    AliGW - The formula is written to do precisely what I have explained but I now have this other problem in that it deletes the duplicates.

  10. #10
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Strange Results From Formula

    And TRIM do not remove spaces between words.

  11. #11
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    Posts
    172

    Re: Strange Results From Formula

    Pete, sorry I should have been more specific and said multiple spaces between words.

  12. #12
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    Posts
    172

    Re: Strange Results From Formula

    So the question is - does anyone know of a way that I can remove JUSTthe leading and trailing spaces? Thanks

  13. #13
    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,258

    Re: Strange Results From Formula

    Try ...

    =MID(B3,FIND("\",B3,1),LOOKUP(2,1/(MID(B3,ROW(INDIRECT("1:"&LEN(B3))),1)<>" "),ROW(INDIRECT("1:"&LEN(B3))))-FIND("\",B3,1)+1)

  14. #14
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Strange Results From Formula

    =MID(LEFT(B3,SEARCH(REPT("^",10),SUBSTITUTE(B3," ","^")&REPT("^",10))-1),SEARCH("\",B3),256)
    Please Login or Register  to view this content.
    Try this and copy towards down
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  15. #15
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    Posts
    172

    Re: Strange Results From Formula

    John & NFL thank you both for your solutions they both work a treat. I will mark as solved.

+ 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. COS not working and strange results
    By fesan in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-23-2015, 02:50 AM
  2. [SOLVED] Strange problem with formula results-
    By excelaron in forum Excel General
    Replies: 6
    Last Post: 07-17-2012, 07:51 PM
  3. Strange RAND results
    By tangent1 in forum Excel General
    Replies: 3
    Last Post: 05-08-2010, 11:23 AM
  4. VLOOKUP - Strange results
    By paulwelburn in forum Excel General
    Replies: 6
    Last Post: 05-31-2007, 05:41 PM
  5. [SOLVED] Strange vlookup results
    By Mary-Lou in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-01-2006, 10:50 PM
  6. [SOLVED] Strange results...
    By Jim May in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2006, 05:30 PM
  7. Strange IF results
    By MWE in forum Excel General
    Replies: 0
    Last Post: 03-25-2005, 08:14 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