+ Reply to Thread
Results 1 to 16 of 16

Trimming cells (not spaces)

  1. #1
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136

    Trimming cells (not spaces)

    Afternoon all,
    Let's say in a cell i have the text ABCD/0123/01234 or ABC/0123/012345
    How would i go about extracting whatever is inbetween the / ? i.e. 0123 in both examples??
    Ta muchly
    Last edited by TheRetroChief; 10-29-2008 at 08:00 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,361
    =mid(a1,find("/",a1)+1,find("~",substitute(a1,"/","~",2))-find("/",a1)-1)
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    Top drawer, works a treat.
    As i like to understand and learn from these forums rather than just get an answer, when you have a moment, would you mind quickly running through what each part of the formula does exactly so i can understand and adapt for future?
    Muchos Gracias

  4. #4
    Forum Contributor snasui's Avatar
    Join Date
    07-15-2007
    Location
    Songkhla, Thailand
    MS-Off Ver
    2010, 365
    Posts
    167
    Another,
    Please Login or Register  to view this content.
    Hope this helps.
    Last edited by snasui; 10-20-2008 at 10:55 AM.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,361
    =mid(a1,find("/",a1)+1,find("~",substitute(a1,"/","~",2))-find("/",a1)-1)


    MID function returns text from specified start point for specific length.

    So specified start is determined by using

    find("/",a1)+1

    In order to determine length we need to find second occurance of / and substract first occurance. So in order to find the 2nd occurances I used substitute to change the character to one not normally found in cells.

    substitute(a1,"/","~",2)

    Then we can use a Find to locate the ~ character.

  6. #6
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    Ah. Clever!

    So if there were three i'd have to substitute the third for something else?

    If i wanted to create a date in the form of mm/yy from what was generated, how could i incorporate putting a date seperator (/?) in the middle?? e.g. ABCD/0908/01234 becomes 09/08 or September 2008 or whatever?

  7. #7
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    Never mind.....i've done it with =left(cell,2)&"/"&right(cell,2) !!!

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,361
    If the 4 characters between / are to be used then

    =MID(A1,FIND("/",A1)+1,2) &"/"&MID(A1,FIND("~",SUBSTITUTE(A1,"/","~",2))-2,2)

  9. #9
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    That's the beauty:
    =LEFT(MID(AI2,FIND("/",AI2)+1,FIND("~",SUBSTITUTE(AI2,"/","~",2))-FIND("/",AI2)-1),2)&"/"&(RIGHT(MID(AI2,FIND("/",AI2)+1,FIND("~",SUBSTITUTE(AI2,"/","~",2))-FIND("/",AI2)-1),2))

    Where AI2=cell with the text in.

    Result.

  10. #10
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    Mine looks more impressive!!!! haha

  11. #11
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    PROBLEM!!!!

    The resultant text in the cell (theoretically mm/yy) for some reason cannot be interpreted as a date.

    Basically what i want to do is check if the date generated is before July 07,
    i have 07/07 (July 2007) in cell AP1 with your formula in AP2 it looks at the cells in AI to get the the four-figure number and change it to a date.
    Formatting has no effect.

  12. #12
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,578
    The result will be taken by Excel to be a string (text). Add +0 to your formula and Excel will see it as a number/date. Does that work?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  13. #13
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    Sneaky...yes that fixes it. Good shout!!!

  14. #14
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    Tell a lie....it interprets all the dates as 2008. So no, not quite!!!

  15. #15
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    Thanks guys, I've bodged it as follows....

    If in AI2 i have

    ABCD/0607/01234

    In AP2 i have
    =(MID(AI2,FIND("/",AI2)+1,2)&"/"&(MID(AI2,FIND("/",AI2)+1,2)&"/"&MID(AI2,FIND("~",SUBSTITUTE(AI2,"/","~",2))-2,2)))+0

    This returns the date 06/06/07

    In AQ2 i have
    =IF(AP2<$AP$1,"Exclude","Include")

    in AP1 i have 01/07/07

    It's not ideal, but seems to work!!

  16. #16
    Forum Contributor TheRetroChief's Avatar
    Join Date
    09-30-2008
    Location
    UK
    MS-Off Ver
    2019
    Posts
    136
    the above returned "Exclude" by the way, which is correct!

+ 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. Custom VB Written Message for Protected Cells
    By robertguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2013, 04:09 PM
  2. Formatting Cells - Width
    By drurjs2344 in forum Excel General
    Replies: 4
    Last Post: 09-15-2008, 02:15 PM
  3. Counting Cells by font color problem
    By markwilest in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2007, 12:14 PM
  4. Replies: 2
    Last Post: 03-01-2007, 04:51 PM
  5. [SOLVED] Placing a formula into merged cells!!!
    By ghostly1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2007, 10:55 AM

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