+ Reply to Thread
Results 1 to 12 of 12

Search and Replace in VBA Using Non English Characters

  1. #1
    Registered User
    Join Date
    04-25-2022
    Location
    Caledon, ON, Canada
    MS-Off Ver
    MS Office 365
    Posts
    13

    Search and Replace in VBA Using Non English Characters

    Hello, I am not sure where to post this question so trying here.

    I have an Excel spreadsheet which I download from a website daily which contains "foreign" characters in some names. An example is "ň" which is Czech. The "foreign" character renders correctly in the spreadsheet but when I paste it into a macro which will perform a search and replace the "foreign" character appears as "?" instead of "ň". I have installed the Czech language plug-in for Excel but this has not solved my problem.

    Would anyone know how to search for "ň" and replace with the letter "n"? Is there another plugin for VBA in Excel? The replaced character is used in a vlookup within the VBA macro so has to be changed in order for the vlookup to work as planned.

    Other names containing the same accent "č", react with a "?" as well.

    I hope this makes sense.

    Thanks,

    Dave

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Search and Replace in VBA Using Non English Characters

    There is no way to enter these characters directly into the VBA editor (that I have ever seen). You will have to write a line of code for each character you want to replace.

    You have to determine the Unicode numeric code for each character and then replace with the desired substitute. Here is the code for ň

    You can enter the characters into a worksheet and use the UNICODE function to find the numeric value.

    Please Login or Register  to view this content.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,153

    Re: Search and Replace in VBA Using Non English Characters

    Quote Originally Posted by thestampdad View Post
    ...An example is "ň" which is Czech ...
    ... Would anyone know how to search for "ň" and replace with the letter "n"? ...
    Have you tried it like this below ?

    1. System settings
    Start => Control Panel => Regional and Language options => Administrative tab => Language for non-Unicode programs => Change system locale => Czech

    2. Editor vba
    Tools => Options => Editor format => Font: => Some_Font (Central Europe)

  4. #4
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Search and Replace in VBA Using Non English Characters

    Try UDF like this:

    Please Login or Register  to view this content.
    Usage:

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

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


    C
    9
    Soucasná vláda je u moci proto, že se tak rozhodlo dostatecné množství volicu. Dostatecné množství volicu se tak rozhodlo proto, že melo jako základní cíl...
    10
    Soucasna vlada je u moci proto, ze se tak rozhodlo dostatecne mnozstvi volicu. Dostatecne mnozstvi volicu se tak rozhodlo proto, ze melo jako zakladni cil...


    p.s. text in example is absolutely random from one of czech website.
    Last edited by KOKOSEK; 04-24-2023 at 07:35 AM.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  5. #5
    Registered User
    Join Date
    04-25-2022
    Location
    Caledon, ON, Canada
    MS-Off Ver
    MS Office 365
    Posts
    13

    Re: Search and Replace in VBA Using Non English Characters

    Quote Originally Posted by 6StringJazzer View Post
    There is no way to enter these characters directly into the VBA editor (that I have ever seen). You will have to write a line of code for each character you want to replace.

    You have to determine the Unicode numeric code for each character and then replace with the desired substitute. Here is the code for ň

    You can enter the characters into a worksheet and use the UNICODE function to find the numeric value.

    Please Login or Register  to view this content.
    Thank you, this worked well.

    Dave

  6. #6
    Registered User
    Join Date
    04-25-2022
    Location
    Caledon, ON, Canada
    MS-Off Ver
    MS Office 365
    Posts
    13

    Re: Search and Replace in VBA Using Non English Characters

    Thank you for the suggestion. I was leery of changing my settings in case there would be unwanted changes elsewhere so I did not attempt this change.

    Dave

  7. #7
    Registered User
    Join Date
    04-25-2022
    Location
    Caledon, ON, Canada
    MS-Off Ver
    MS Office 365
    Posts
    13

    Re: Search and Replace in VBA Using Non English Characters

    Thank you for the thorough code, unfortunately I could not get it to run. Not sure why. I put the code in the sheet I was working on, ran the code but it did not replace anything and no error messages. I am a beginner when it comes to VBA and most of my code is created by recording it. I did find that 6StringJazzer's example worked for my purposes.

    Dave

  8. #8
    Registered User
    Join Date
    04-25-2022
    Location
    Caledon, ON, Canada
    MS-Off Ver
    MS Office 365
    Posts
    13

    Re: Search and Replace in VBA Using Non English Characters

    Quote Originally Posted by KOKOSEK View Post
    Try UDF like this:

    Please Login or Register  to view this content.
    Usage:

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

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


    C
    9
    Soucasná vláda je u moci proto, že se tak rozhodlo dostatecné množství volicu. Dostatecné množství volicu se tak rozhodlo proto, že melo jako základní cíl...
    10
    Soucasna vlada je u moci proto, ze se tak rozhodlo dostatecne mnozstvi volicu. Dostatecne mnozstvi volicu se tak rozhodlo proto, ze melo jako zakladni cil...


    p.s. text in example is absolutely random from one of czech website.
    Thank you for the thorough code, unfortunately I could not get it to run. Not sure why. I put the code in the sheet I was working on, ran the code but it did not replace anything and no error messages. I am a beginner when it comes to VBA and most of my code is created by recording it. I did find that 6StringJazzer's example worked for my purposes.

    Dave

  9. #9
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Search and Replace in VBA Using Non English Characters

    As first, please do not quote full post.
    In excel press Alt+F11, it should open additional window with VBA editor, something like below:
    Capture.JPG
    then click with right mouse button and choose Insert->Module like on picture above

    Then paste into main part of window code of function from my post (Public Function Sanitize..........) like below:
    1Capture.JPG

    When you back to excel, you can use it as:
    Please Login or Register  to view this content.
    excel file have to be save as file with macro (xlsm).

  10. #10
    Registered User
    Join Date
    04-25-2022
    Location
    Caledon, ON, Canada
    MS-Off Ver
    MS Office 365
    Posts
    13

    Re: Search and Replace in VBA Using Non English Characters

    Thank you KOKOSEK, that worked very well. One small thing that it does not do is maintain the Case of the letter, how do I match lowercase or uppercase? The example I gave happened to be lower case but there are other characters such as "Ĉ" that need to remain in uppercase once the conversion is done.

    Thank you again.

    Dave

  11. #11
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Search and Replace in VBA Using Non English Characters

    Put some examples of texts with characters which you want to convert into excel file and attach here into your post (check yellow banner at the top of the page). It will help to identify characters which we are looking for the most (Czech I suppose).
    It should not be hard to add another characters into this code.

    p.s. for "Ĉ" I've found a code, just replace this line:

    Please Login or Register  to view this content.
    Last edited by KOKOSEK; 04-25-2023 at 11:25 AM.

  12. #12
    Registered User
    Join Date
    04-25-2022
    Location
    Caledon, ON, Canada
    MS-Off Ver
    MS Office 365
    Posts
    13

    Re: Search and Replace in VBA Using Non English Characters

    Thank you again KOKOSEK. Unfortunately, the file I download is a dynamic one and can change from day to day. It contains a list of Professional Hockey Players from the NHL and there are players from many countries who are listed with their countries characters in some cases. I don't have any new ones at the moment.

    I did take some time and digested what you have in the 2 main lines of code and can see that the first line is the ChrW set and the second is the corresponding English alpha equivalent. I saw that you added for "Ĉ" (268, 67) which is appreciated. As I come across new combinations I will add it to the code you provided. I found a very extensive list online https://stackoverflow.com/questions/...code-character. Someone posted a macro here that creates all the possible conversions into an Excel spreadsheet. I found this very useful to see what your code is doing.

    Thank you again very much for taking the time to help me with this.

    Dave

+ 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. search within text file and replace strings with variable number of characters
    By ingolf_ingolfsen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 03:54 AM
  2. Macro to replace European characters with non "special" English characters?
    By johanna0507 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2012, 09:13 AM
  3. Search for and replace last X number of characters
    By garden_gnome in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2012, 05:15 AM
  4. Foreign (non-English) characters in VBA
    By justforgroups in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2010, 06:48 PM
  5. How to handle non-english characters in VBA?
    By Zepher in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2009, 11:19 PM
  6. search and replace special characters
    By jmhultin in forum Excel General
    Replies: 2
    Last Post: 10-14-2009, 12:07 PM
  7. Search and Replace characters...
    By Ham in forum Excel General
    Replies: 1
    Last Post: 02-09-2007, 01:05 PM
  8. [SOLVED] Search and replace for non printable characters
    By ricl999 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2005, 07:06 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