Consulting

Results 1 to 16 of 16

Thread: Non-Printing Characters: Box with a Question Mark Unable to remove

  1. #1
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location

    Non-Printing Characters: Box with a Question Mark Unable to remove

    Hi Good afternoon to all of you from Sri Lanka,

    I am trying to remove the above mentioned square which is around a Question Mark.

    Please refer attachment for sample.

    My version is office 2016.

    Please help Thank you.Unicode issue.xlsx

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    From here

    The problem is that you are working with double byte or unicode text. The CODE function only works with ASCII (single byte) text so it is only picking up part of the two byte character.

    The only way I can think of doing this is to use functions that handle unicode text and put a copy of the "white space" double byte character in a special cell so we can use it.

    This formula works:

    =SUBSTITUTE(A2,O$1,"")

    assuming you have a copy of the "white space" character in O1.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Here's a UDF to remove the character
    Function MyClean(Data)
        MyClean = Replace(Data, ChrW(&HE04C), "")
    End Function
    I made up this to determine the character which was copied into another cell.
    Sub FindUnicode()
    For i = 1 To 128000
    If InStr(1, ActiveCell, ChrW("&H" & Hex(i))) Then Exit For
    Next
    ActiveCell.Offset(, 1) = Hex(i)
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location
    Quote Originally Posted by mdmackillop View Post
    Here's a UDF to remove the character
    Function MyClean(Data)
        MyClean = Replace(Data, ChrW(&HE04C), "")
    End Function
    I made up this to determine the character which was copied into another cell.
    Sub FindUnicode()
    For i = 1 To 128000
    If InStr(1, ActiveCell, ChrW("&H" & Hex(i))) Then Exit For
    Next
    ActiveCell.Offset(, 1) = Hex(i)
    End Sub
    Thanks a lot for your response, in another forum, a user suggested this equation,

    =IF(ISNUMBER(LEFT(C11)+0),C11,REPLACE(C11,1,1,""))

    Now this works really well as far as the character I have mentioned is in the left hand side, problem is I sometime have the character in the right hand side end as well.

    I have no clue how to use the VB which is mentioned above bro.

    How do I run it?

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    MYClean is used like a normal function. It is added to a code module in the workbook. If you don't use VBA, you'll need to add the Developer tab to the ribbon to access it. You can rename it if you want.
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    As you have posted this in another forum. please provide links in both forums to the other posts
    Please read this
    I've renamed your question to make it a more general application.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location
    Quote Originally Posted by mdmackillop View Post
    MYClean is used like a normal function. It is added to a code module in the workbook. If you don't use VBA, you'll need to add the Developer tab to the ribbon to access it. You can rename it if you want.
    Wowwwww ! You are a genius aren't you?

    Ok, I checked the attached worksheet and understood what you tried to achieve by the first micro,

    What was the second part for? what exactly does it do and how do I use it in the same WORKBOOK?

    Because, in the workbook which was attached, I found only the 1st part of your equation was mentioned in the module,

    the part you said,

    "I made up this to determine the character which was copied into another cell."

    you haven't added that.

    Why and what exactly does that coding do? Please apologize this Newbie
    Last edited by New_Here; 04-16-2017 at 03:38 AM.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you have a similar character, place it on its own in a cell and run FindUnicode. It should show the Hexadecimal for that character in the adjoining cell. That value can be used in the MyClean routine.
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location
    Quote Originally Posted by mdmackillop View Post
    If you have a similar character, place it on its own in a cell and run FindUnicode. It should show the Hexadecimal for that character in the adjoining cell. That value can be used in the MyClean routine.
    I came across a small issue, the myclean doesnt seem to work in all cells. Why is that? please refer attachment.

    That says a E185 :/

    If you could let me know how the 1st vba module needs to be re-adjusted that would be great, so that I will be able to look at other similar codes as well and apply the same.
    Attached Files Attached Files

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Add characters to the array as required
    Your workbook needs to be saved as an XLSM file to contain the macro coding.

    Function MyClean(Data)
        Dim arr, a
        arr = Array(&HE185, &HE04C)
        For Each a In arr
        Data = Replace(Data, ChrW(a), "")
        Next a
        MyClean = Data
    End Function
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    If it's ALWAYS in the first position, something like this would work


    =RIGHT(C11,LEN(C11)-1)

    Otherwise you need something more complicated like Mac's
    ---------------------------------------------------------------------------------------------------------------------

    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

  12. #12
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location
    Quote Originally Posted by Paul_Hossler View Post
    If it's ALWAYS in the first position, something like this would work


    =RIGHT(C11,LEN(C11)-1)

    Otherwise you need something more complicated like Mac's
    I finally managed to solve the matter by creating multiple VBA codes i.e MyClear1,2,3 etc and filtered a single cell via colomns, so eventually the cell gets caught to one of the error codes.

    Thanks a lot for your support and time.

  13. #13
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location
    Quote Originally Posted by mdmackillop View Post
    Add characters to the array as required
    Your workbook needs to be saved as an XLSM file to contain the macro coding.

    Function MyClean(Data)
        Dim arr, a
        arr = Array(&HE185, &HE04C)
        For Each a In arr
        Data = Replace(Data, ChrW(a), "")
        Next a
        MyClean = Data
    End Function
    EXACTLY BROTHER ! EXACTLY .... This is what I needed, but due to time restrains I finally managed to solve the matter by creating multiple VBA codes i.e MyClear1,2,3 etc and filtered a single cell via colomns, so eventually the cell gets caught to one of the error codes.

    Thanks a lot for your support and time.

    I will update to this code once I have completed my current task.

    Thank you again and I apologize if I had troubled you.

  14. #14
    Another approach is instead of trying to exclude characters you don't want, is to instead only include the character you do want. Phone numbers lend themselves well to this.

    Function CleanContactNumber(ContactNumber, LegalCharacters As String) As String
        Dim Ch As String, CleanNumber As String
        Dim NumStr As String
        Dim I As Long
    
        NumStr = CStr(ContactNumber)
        CleanNumber = ""
        For I = 1 To Len(NumStr)
            Ch = Mid(NumStr, I, 1)
            If InStr(LegalCharacters, Ch) Then
                CleanNumber = CleanNumber & Ch
            End If
        Next I
        CleanContactNumber = CleanNumber
    End Function
    So the cell formula would be

    =CleanContactNumber(C11,"0123456789-")

    Where "0123456789-" are the legal characters.
    Attached Files Attached Files
    Last edited by rlv; 04-16-2017 at 08:06 AM. Reason: typo in function

  15. #15
    oops. Minor function error. I was in too much of a hurry. This line was erroneously inside the loop.

    CleanContactNumber = CleanNumber
    Corrected above and reposting the file here.
    Attached Files Attached Files

  16. #16
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location
    Quote Originally Posted by rlv View Post
    oops. Minor function error. I was in too much of a hurry. This line was erroneously inside the loop.

    CleanContactNumber = CleanNumber
    Corrected above and reposting the file here.
    Wow !!!

    You guys seems to be having excel equations for Food.

    So many methods to tackle one issue.

    Thanks a lot brother for your kind support for this helpless Guy

    But I will have to go with mdmackillops method because there are instances where these symbols seem to appear on addresses and many other character fields.

    NEVERTHELESS your equation and effort will not go in vain, its saved for my future reference as I am a collector A Big Thank you for all you amazing people. Bye.

Posting Permissions

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