+ Reply to Thread
Results 1 to 10 of 10

Selecting the 5th and 6th characters from right end of a string

  1. #1
    Registered User
    Join Date
    02-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Selecting the 5th and 6th characters from right end of a string

    Hi, despite googling the heck out of this, I've so far failed to find a solution to what, I think, should be a relatively straightforward excel query.

    I have variable length strings, as shown in the sample cells below

    Topography\TAB_Format\SP9200
    Topography\TAB_Format\SP9400
    OS_Data\Landline
    ITN\TileTab\TQ2286


    I want to select any record where 5th and 6th character from the right hand end of the string which = either "SP" or "TQ". Where this is the case I'm then looking to truncate the string to remove the last 7 chacters.

    Can someone please advise on the kind of formula I should be using? None of what I have so far found using mid or right string appears to be particularly applicable.

    Any advice on this would be much appreciated. Thanks

  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: Selecting the 5th and 6th characters from right end of a string

    Maybe this...

    Data Range
    A
    B
    2
    Topography\TAB_Format\SP9200
    Topography\TAB_Format
    3
    Topography\TAB_Format\SP9400
    Topography\TAB_Format
    4
    OS_Data\Landline
    OS_Data\Landline
    5
    ITN\TileTab\TQ2286
    ITN\TileTab


    This formula entered in B2 and copied down:

    =IF(OR(LEFT(RIGHT(A2,6),2)={"SP","TQ"}),LEFT(A2,LEN(A2)-7),A2)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Selecting the 5th and 6th characters from right end of a string

    Or this

    =IFERROR(IF(FIND("SP",A1)>0,LEFT(A1,LEN(A1)-7)),IFERROR(IF(FIND("TQ",A1)>0,LEFT(A1,LEN(A1)-7),A1),A1))
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Registered User
    Join Date
    12-03-2013
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Selecting the 5th and 6th characters from right end of a string

    =LEFT(A1,LEN(A1)-7) This will give you the stripped down text

    Then, use the autofilter to filter out the "\SP" and "\TQ" data. Choose the 'contains' option in the filter.

  5. #5
    Registered User
    Join Date
    02-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Selecting the 5th and 6th characters from right end of a string

    Quote Originally Posted by Tony Valko View Post
    Maybe this...

    This formula entered in B2 and copied down:

    =IF(OR(LEFT(RIGHT(A2,6),2)={"SP","TQ"}),LEFT(A2,LEN(A2)-7),A2)
    That worked a treat - thanks Biff.

    Thanks to everyone else too who respoonded, this one fits best with my (albeit limited) understanding of how excel formulas work.

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

    Re: Selecting the 5th and 6th characters from right end of a string

    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

  7. #7
    Registered User
    Join Date
    02-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Selecting the 5th and 6th characters from right end of a string

    Quote Originally Posted by Tony Valko View Post
    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.
    No worries, and cheers for the steer on management of threads

  8. #8
    Registered User
    Join Date
    02-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Selecting the 5th and 6th characters from right end of a string

    I'm now trying to apply BIFFS formula =IF(OR(LEFT(RIGHT(A2,6),2)={"SP","TQ"}),LEFT(A2,LEN(A2)-7),A2) to a longer string, and for some reason it doesn't seem to work.

    here's the string in question:
    \vol\vnf9_data13\vnf9_data13\Data_Library\Mapping\OS_Data\MasterMap\Topography\TAB_Format\SP9200

    Applying the formula fails to remove the last 7 characters as it did before.

    Can anyone explain how (and why) the formula can be amended to accomodate the longer string? I can't understand why it doesn't work on the longer string (if indeed this is the problem) as all the counting is started from the right?


    thanks
    Last edited by davo66; 02-25-2014 at 05:54 AM. Reason: typo

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Selecting the 5th and 6th characters from right end of a string

    Hi,

    Just tested on that string and works absolutely fine for me.

    Perhaps you can post a workbook with your attempt so that we can see what may be the issue?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  10. #10
    Registered User
    Join Date
    02-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Selecting the 5th and 6th characters from right end of a string

    I've got it working too now - it was a silly typo - nothing to do with string length at all.

    Thanks,

    Dave

+ 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. Selecting letters/characters/numbers separately for a filter
    By WasWodge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2014, 09:12 PM
  2. [SOLVED] Extract left characters from string with exception of 2 right characters
    By sweetkel23 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-16-2012, 10:45 PM
  3. Solved: Selecting Definite Number of Characters in a Cell
    By clawrence04 in forum Excel General
    Replies: 7
    Last Post: 03-21-2009, 02:32 PM
  4. Selecting only certain characters from a cell value?
    By drucey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-20-2006, 08:23 AM
  5. Replies: 0
    Last Post: 08-29-2005, 11:03 AM

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