+ Reply to Thread
Results 1 to 6 of 6

How to detect leading or trailing apostrophe and quote characters

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    How to detect leading or trailing apostrophe and quote characters

    Hi All,

    I've not had a lot of luck trying to resolve this via Google searches so I'm opening this one out to you guys.

    The problem is simple. I want to alert a user that he or she has typed in a text string that begins or ends with an apostrophe ' or begins or ends with a quotation mark " so that they can take corrective action in removing these characters. The reasons for this are superflous to this post but what I thought was a logical answer returns a formula error. Here's the scenario:-

    A user enters a string of text in cell A1.

    Cell B1 checks if the text, if any, in A1 begins or ends with a ' or a " and if it does, returns an "Error" message

    The formula I've tried in B1 is =IF(OR(LEFT(A1,1)="'",LEFT(A1,1)=""",RIGHT(A1,1)="'",RIGHT(A1,1)=""")),"Error","Ok") but Excel will have none of it

    Has anyone come across this scenario and found a solution.

    Many thanks.

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

    Re: How to detect leading or trailing apostrophe and quote characters

    Hi,

    One of the issues you have is that Excel treats a leading single apostrophe as indicating that that cell's contents should be treated as text, though the single apostrophe itself is not physically entered as part of the text.

    How are you accounting for this in your set-up? Do you mean it's possible that users may enter two leading apostrophes?

    Regards
    Click * below if this answer helped

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

  3. #3
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: How to detect leading or trailing apostrophe and quote characters

    Hi

    Thanks for replying. It actually doesn't matter how many leading or trailing apostrophes are entered, just the fact that an apostrophe exists at the start or end of the text so the user can remove it from the text string. Is there a way of bypassing how Excel treats a leading apostrophe so that the user is alerted?

  4. #4
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: How to detect leading or trailing apostrophe and quote characters

    Hi

    Thanks for replying. It actually doesn't matter how many leading or trailing apostrophes are entered, just the fact that an apostrophe exists at the start or end of the text so the user can remove it from the text string. Is there a way of bypassing how Excel treats a leading apostrophe so that the user is alerted?

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

    Re: How to detect leading or trailing apostrophe and quote characters

    Try:

    =IF(OR(LEFT(A1)={"""","'"},RIGHT(A1)={"""","'"}),"Error","Ok")

    or

    =IF(OR(MID(A1,LEN(A1)^{0;1},1)={"""","'"}),"Error","Ok")

    Regards

  6. #6
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: How to detect leading or trailing apostrophe and quote characters

    [Duplicate posted in error - irgnore]
    Last edited by kyjae; 06-23-2014 at 07:38 AM. Reason: Duplicate posted in erro

  7. #7
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: How to detect leading or trailing apostrophe and quote characters

    Thanks,
    I'll try the formulae you've suggested. Would you be able to explain the logic behind the forlmulae as I'm not familair with these functions or the use of curly brackets.

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

    Re: How to detect leading or trailing apostrophe and quote characters

    It's just useful to condense the formula slightly. The first could equally be written:

    =IF(OR(LEFT(A1)="""",LEFT(A1)="'",RIGHT(A1)="""",RIGHT(A1)="'"),"Error","Ok")

    if you find it easier to understand.

    Regards

  9. #9
    Registered User
    Join Date
    10-04-2012
    Location
    Not here, it's rubbish!
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    66

    Re: How to detect leading or trailing apostrophe and quote characters

    All sorted. Many thanks.

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

    Re: How to detect leading or trailing apostrophe and quote characters

    You're welcome.

+ 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. Need to start a cell with an apostrophe/single quote
    By ChicagoTRS in forum Excel General
    Replies: 5
    Last Post: 09-20-2019, 11:36 PM
  2. Remove a leading Apostrophe
    By John Bates in forum Excel General
    Replies: 10
    Last Post: 09-09-2014, 07:41 AM
  3. iNSERT LEADING APOSTROPHE
    By uncreative in forum Excel General
    Replies: 3
    Last Post: 03-29-2006, 08:10 PM
  4. Double Quote Leading to Apostrophe Problem
    By ToferKing in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-27-2006, 11:45 AM
  5. detect and remove apostrophe
    By ilyaskazi in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-17-2005, 01:18 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