Eliminating diacritics

There are some situations when we need to use, in MS Office applications (eg Excel), certain words without diacritics. In VBA we can do this relatively easily, using such a function (ExtendOffice):

The problem is that, if we look carefully, we don’t really find the ones used in the Romanian language (“ş”, “ţ”, ă). If we want to enter them in VBA we will notice that they are automatically converted to other characters.

To avoid such stress, an elegant solution is to use ASCII codes. Because not all Romanian diacritics are part of the original ASCII set, we will resort to the extended Unicode character set. It helps to use Chr$ (for ASCII) and ChrW (for Unicode) functions.

Therefore, I allowed myself to adapt the code above, “romanizing” it and regarding the variable name, in order to be as understandable as possible their action.

Of course, if we are interested in other letters with different accents that we want to convert to, we can add them to those vectors.

If in Excel we can use this function, if we use Google Sheets, we can convert the function into compatible code. For this we should follow the steps:

  1. In the Extensions menu we choose Apps Script.
  2. In the Apps Script editor, weadd the code below.
  1. We save the script and project.
  2. In Google Sheets, we will write like this: =diacrit("B2") 

Author: Ovidiu.S

I am quite passionate about this professional area as if I know something - no matter how little - I want to share it with others.

Leave a Reply

Your email address will not be published. Required fields are marked *