Consulting

Results 1 to 7 of 7

Thread: Missing apostrophe

  1. #1
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location

    Missing apostrophe

    Hi guys

    I am working on an excel worksheet where the data has been imported from another database over which I have zero control. There are 2 descriptive fields containing text which often contain apostrophes input into the original database by a multitude of users. The apostrophes are never at the beginning of the field. (usually denotes possession as in < the girl's hat > )
    The problem is that some apostrophes appear in Excel and some do not. The same record field sometimes contains one apostrophe but another one is missing.
    In Excel, you cannot see a space, but if you put the cursor where the apostrophe should be, there is a (very thin!) character there that Excel does not display. I used ctrl+c and pasted this into Find&Replace and I can replace this character by doing this, but I want to automate this process via a macro and have failed miserably!
    I used the CODE function, and that suggests that the ascii character is 146. But if I put this into vba and ask for chr(146) to be replaced , it does nothing. The code I used (which works if I try to replace other characters) is

    Worksheets("Sheet2").Columns("K:L").Replace What:=Chr(146), Replacement:="XXX", LookAt:=xlPart, _
    SearchOrder:=xlByColumns, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False

    If pasted into Word, the apostrophe is also missing but there is a visible space. Word does not recognise it as a space (hops over it if I use search and replace with ^w). Again the ctrl+c trick (mentioned above) works.

    As an example of my problem, in the attached 2 files there should be an apostrophe between "Britain" and "s".

    Any ideas as to what else I can try?
    Hopefully I have posted correctly - this is my first attempt.
    Thanks
    Yon
    Attached Files Attached Files

  2. #2
    VBAX Regular
    Joined
    Feb 2013
    Posts
    52
    Location
    Running this bit of code on what you posted in the .xlsx, on my computer it is chr(63)
    Sub CheckOfCharacters()
        Dim i As Integer
        Dim str As String
    
    str = ActiveCell.Value
    
        For i = 1 To Len(str)
            Debug.Print Mid(str, i, 1) & "  =  " & Asc(Mid(str, i, 1))
        Next
    
    End Sub

  3. #3
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    Thanks NoSparks for your help but Excel does not believe that either. I ran =SUBSTITUTE(L8,CHAR(63),"xxx") against various cells containing the missing apostrophe and Excel still refuses to do replace anything! Macro also.
    Any other ideas
    thank you
    Yon

  4. #4
    VBAX Regular
    Joined
    Feb 2013
    Posts
    52
    Location
    There has been a discussion on one of the other Excel forums in the last few days of something somewhat similar dealing with chr(216) which is Ø. I haven't been able to relocate it yet to see if anything there would be of relevance.

  5. #5
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    Thanks NoSparks.
    This seems to be one of those frustrating problem which appear obvious but for some reason are not!
    Yon

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Use

    What:=ChrW(146)

    and see

    You're dealing with Unicode Wide characters
    Attached Files Attached Files
    Last edited by Paul_Hossler; 02-24-2015 at 11:51 AM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    Thank you Paul. Absolutely spot on!!
    Yon

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •