+ Reply to Thread
Results 1 to 15 of 15

Removing leading AND trailing apostrophes from a text string

  1. #1
    Registered User
    Join Date
    11-15-2012
    Location
    Brisbane, Queensland
    MS-Off Ver
    Excel 2013
    Posts
    14

    Removing leading AND trailing apostrophes from a text string

    Hi all and I'm hoping there's someone here who's had this problem.

    I regularly receive extracts from a database in CSV format.
    Until recently there were no real issues, just a few simple reformats and I could roll the data into my spreadsheet.
    Then someone at the other end decided to change the extraction algorithm and the CSV now encapsulates text strings within apostrophes:

    ' Australian Women's Weekly Children's Birthday Cakes '

    My question is; how do I get rid of the 2 outer apostrophes while leaving the 2 inner ones in place?
    Output needs to become:

    Australian Women's Weekly Children's Birthday Cakes

    I match these title strings with a stock list and unfortunately stock codes are not an option due to CSV report field limitations.
    As I have several years of existing data it would be a massive undertaking to reconcile these two different data types.
    All I really want to do is "clean up" the CSV data before pasting it into the master xlsx spreadsheet.

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

    Re: Removing leading AND trailing apostrophes from a text string

    Use PowerQuery and remove first 'and (space) and last (space) and '

  3. #3
    Forum Expert cbatrody's Avatar
    Join Date
    04-15-2014
    Location
    Dubai
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2,136

    Re: Removing leading AND trailing apostrophes from a text string

    OR,

    Try the following:

    =SUBSTITUTE(SUBSTITUTE(A1," ' ",""),"' ","")

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

    Re: Removing leading AND trailing apostrophes from a text string

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


    note: there is a space before E( because of sucuri firewall

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,015

    Re: Removing leading AND trailing apostrophes from a text string

    You can do this with two passes of Find & Replace if the spaces are there as you show in your example.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  6. #6
    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: Removing leading AND trailing apostrophes from a text string

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

    v A B
    1 Australian Women's Weekly Children's Birthday Cakes ' Australian Women's Weekly Children's Birthday Cakes
    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

  7. #7
    Registered User
    Join Date
    11-15-2012
    Location
    Brisbane, Queensland
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Removing leading AND trailing apostrophes from a text string

    Thanks for all your help but I've now discovered that the effect is not uniform ie sometimes a lead or trailing apostrophe is NOT included.
    I guess I'm going to have to look at designing a macro instead as any operation will now be conditonal.
    OMG I so loathe sloppy programmers!

  8. #8
    Forum Expert cbatrody's Avatar
    Join Date
    04-15-2014
    Location
    Dubai
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2,136

    Re: Removing leading AND trailing apostrophes from a text string

    Did you try the following?

    Please Login or Register  to view this content.
    It works even if there are random 's in the beginning or at the end.

    See the attached file.
    Attached Files Attached Files

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Removing leading AND trailing apostrophes from a text string

    Alkey will come up with something one tenth the length of this one.... but try:

    =TRIM(IF(RIGHT(IF(LEFT(A1,1)="'",MID(A1,2,255),A1),1)="'",LEFT(IF(LEFT(A1,1)="'",MID(A1,2,255),A1),LEN(IF(LEFT(A1,1)="'",MID(A1,2,255),A1))-1),IF(LEFT(A1,1)="'",MID(A1,2,255),A1)))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

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

    Re: Removing leading AND trailing apostrophes from a text string

    Quote Originally Posted by kazaly View Post
    Thanks for all your help but I've now discovered that the effect is not uniform ie sometimes a lead or trailing apostrophe is NOT included.
    could you give us excel file with more than one, different examples?

  11. #11
    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: Removing leading AND trailing apostrophes from a text string

    This is actually a bit of headache... but here is something that might work.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1 Australian Women's Weekly Children's Birthday Cakes ' Australian Women's Weekly Children's Birthday Cakes
    2 Australian Women's Weekly Children's Birthday Cakes ' Australian Women's Weekly Children's Birthday Cakes
    3 Australian Women's Weekly Children's Birthday Cakes' Australian Women's Weekly Children's Birthday Cakes
    4 Australian Women's Weekly Children's Birthday Cakes Australian Women's Weekly Children's Birthday Cakes
    Attached Files Attached Files

  12. #12
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,742

    Re: Removing leading AND trailing apostrophes from a text string

    Do you suppose this will do it?

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



    A
    B
    1
    Australian Women's Weekly Children's Birthday Cakes '
    Australian Women's Weekly Children's Birthday Cakes
    2
    Australian Women's Weekly Children's Birthday Cakes '
    Australian Women's Weekly Children's Birthday Cakes
    3
    Australian Women's Weekly Children's Birthday Cakes'
    Australian Women's Weekly Children's Birthday Cakes
    4
    Australian Women's Weekly Children's Birthday Cakes
    Australian Women's Weekly Children's Birthday Cakes
    Dave

  13. #13
    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: Removing leading AND trailing apostrophes from a text string

    Quote Originally Posted by FlameRetired View Post
    Do you suppose this will do it?

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



    A
    B
    1
    Australian Women's Weekly Children's Birthday Cakes '
    Australian Women's Weekly Children's Birthday Cakes
    2
    Australian Women's Weekly Children's Birthday Cakes '
    Australian Women's Weekly Children's Birthday Cakes
    3
    Australian Women's Weekly Children's Birthday Cakes'
    Australian Women's Weekly Children's Birthday Cakes
    4
    Australian Women's Weekly Children's Birthday Cakes
    Australian Women's Weekly Children's Birthday Cakes
    That would way be too easy You can't depend on a part of one word ('s"). Otherwise you wold have to make changes to the formula for each sentence.

  14. #14
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,742

    Re: Removing leading AND trailing apostrophes from a text string

    Quote Originally Posted by AlKey View Post
    That would way be too easy You can't depend on a part of one word ('s"). Otherwise you wold have to make changes to the formula for each sentence.
    AlKey I understand, and was afraid of that even if it's "'s " and not "'s". There are others. For example can't, you're or worse plural possessives.

    Still I was hoping to open another approach.

  15. #15
    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: Removing leading AND trailing apostrophes from a text string

    I think this one should do better
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1 Australian Women's Weekly Children's Birthday Cakes' Australian Women's Weekly Children's Birthday Cakes
    2 Australian Women's Weekly Children's Birthday Cakes ' Australian Women's Weekly Children's Birthday Cakes
    3 Australian Women's Weekly Children's Birthday Cakes ' Australian Women's Weekly Children's Birthday Cakes
    4 Australian Women's Weekly Children's Birthday Cakes Australian Women's Weekly Children's Birthday Cakes
    A little bit shorter
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    or even this
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by AlKey; 09-26-2017 at 03:54 PM.

+ 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] Trying to get rid of leading apostrophes in text cells
    By Habanero Time in forum Excel General
    Replies: 13
    Last Post: 12-29-2017, 08:12 PM
  2. Highlight leading and trailing spaces of text within cells
    By runnerD2016 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2016, 09:48 AM
  3. [SOLVED] How to remove all leading and trailing colons (;) from a text?
    By excelhelp2045 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-28-2015, 01:19 AM
  4. Removing leading and trailing / ,
    By araviintl in forum Excel General
    Replies: 6
    Last Post: 05-10-2014, 03:50 AM
  5. Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM
    By Zach51215 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-20-2013, 04:24 PM
  6. [SOLVED] Removing leading and trailing spaces
    By mangesh in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-18-2013, 05:25 AM
  7. [SOLVED] How to save Excel string data without the leading/trailing DQ (")s
    By Patrick Bailey in forum Excel General
    Replies: 1
    Last Post: 02-15-2006, 10:15 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