Formula to remove all accented characters

Hi,
In column B, I have words with accented characters.
In column C, I’d like to write a formula that returns the same word in column B, but replacing the accented characters with unaccented characters. eg. =RemoveAccent(B1)

So bēn in B1 becomes ben in C1

A macro like the below works , but is tedious as I have to add each accented character manually:

Function RemoveAccent(thestring As String)
Dim A As String * 1
Dim B As String * 1
Dim i As Integer
Const AccChars = "ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåâāçḏèéêëēìíîïðñòóôõöṯùúûüûýÿ"
Const RegChars = "szszyaaaaaaceeeeiiiidnooooouuuuyaaaaaaaacdeeeeeiiiidnoooootuuuuuyy"
For i = 1 To Len(AccChars)
A = Mid(AccChars, i, 1)
B = Mid(RegChars, i, 1)
thestring = Replace(thestring, A, B)
Next
RemoveAccent = thestring
End Function

Is there a way to set Const AccChars to all accented characters, and Const RegChars to all unaccented characters (UTF-8?), so I don’t have to type each new one individually?

Hello and welcome!
I’m afraid there is no absolutely precise way to do this - when we come up with and implement something that will work well, somewhere in the world there will definitely be a smart guy who will come up with another letter for which our constants were not designed.
If we believe this code (marked as Beta), then there are not so many of them now, only 459. Maybe it makes sense to list them all and calm down?

It might end up looking terrible, not very resource efficient, prone to bugs in the future… but for now it seems to work:

Function RemoveAccent(ByVal sString As String) As String
Dim aSourceLetters As Variant, aTargetLetters As Variant, i As Long 
	aSourceLetters = Array("À", "Á", "Â", "Ã", "Ä", "Å", "Ấ", "Ắ", "Ẳ", "Ẵ", "Ặ", "Ầ", "Ằ", "Ȃ", "Ả", "Ạ", "Ẩ", "Ẫ", "Ậ", _
	"à", "á", "â", "ã", "ä", "å", "ấ", "ắ", "ẳ", "ẵ", "ặ", "ầ", "ằ", "ȃ", "ả", "ạ", "ẩ", "ẫ", "ậ", "Ā", "ā", _
	"Ă", "ă", "Ą", "ą", "Ǎ", "ǎ", "Ǻ", "ǻ", "A̋", "a̋", "Ȁ", "ȁ", "A̧", "a̧", "Æ", "æ", "Ǽ", "ǽ", _
	"B̌", "b̌", "B̧", "b̧", "Ç", "Ḉ", "ç", "ḉ", "Ć", "ć", "Ĉ", "ĉ", "Ċ", "ċ", "Č", "č", "C̆", "c̆", "Č̣", "č̣", _
	"Ð", "ð", "Ď", "ď", "Đ", "đ", "Ḑ", "ḑ", "È", "É", "Ê", "Ë", "Ế", "Ḗ", "Ề", "Ḕ", "Ḝ", "Ȇ", "Ẻ", "Ẽ", "Ẹ", "Ể", "Ễ", "Ệ", _
	"è", "é", "ê", "ë", "ế", "ḗ", "ề", "ḕ", "ḝ", "ȇ", "ẻ", "ẽ", "ẹ", "ể", "ễ", "ệ", "Ē", "ē", "Ĕ", "ĕ", "Ė", "ė", "Ę", "ę", _
	"Ě", "ě", "E̋", "e̋", "Ȅ", "ȅ", "Ê̌", "ê̌", "Ȩ", "ȩ", "Ɛ̧", "ɛ̧", "ƒ", "F̌", "f̌", _
	"Ĝ", "Ǵ", "ĝ", "ǵ", "Ğ", "ğ", "Ġ", "ġ", "Ģ", "ģ", "Ǧ", "ǧ", "Ĥ", "ĥ", "Ħ", "ħ", "Ḫ", "ḫ", "Ȟ", "ȟ", "Ḩ", "ḩ", _
	"Ì", "Í", "Î", "Ï", "Ḯ", "Ȋ", "Ỉ", "Ị", "ì", "í", "î", "ï", "ḯ", "ȋ", "ỉ", "ị", "Ĩ", "ĩ", "Ī", "ī", "Ĭ", "ĭ", "Į", "į", "İ", "ı", "Ǐ", "ǐ", "I̋", "i̋", "Ȉ", "ȉ", _
	"I̧", "i̧", "Ɨ̧", "ɨ̧", "IJ", "ij", "Ĵ", "ĵ", "J̌", "ǰ", "Ķ", "ķ", "Ḱ", "ḱ", "K̆", "k̆", "Ǩ", "ǩ", "Ĺ", "ĺ", "Ļ", "ļ", "Ľ", "ľ", "Ŀ", "ŀ", "Ł", "ł", _
	"Ḿ", "ḿ", "M̆", "m̆", "M̌", "m̌", "M̧", "m̧", "Ñ", "ñ", "Ń", "ń", "Ņ", "ņ", "Ň", "ň", "ʼn", "N̆", "n̆", "Ǹ", "ǹ", _
	"Ò", "Ó", "Ô", "Õ", "Ö", "Ø", "Ố", "Ṍ", "Ṓ", "Ȏ", "Ỏ", "Ọ", "Ổ", "Ỗ", "Ộ", "Ờ", "Ở", "Ỡ", "Ớ", "Ợ", _
	"ò", "ó", "ô", "õ", "ö", "ø", "ố", "ṍ", "ṓ", "ȏ", "ỏ", "ọ", "ổ", "ỗ", "ộ", "ờ", "ở", "ỡ", "ớ", "ợ", "Ō", "ō", _
	"Ŏ", "ŏ", "Ő", "ő", "Ơ", "ơ", "Ǒ", "ǒ", "Ǿ", "ǿ", "Ồ", "ồ", "Ṑ", "ṑ", "Ȍ", "ȍ", "O̧", "o̧", "Œ", "œ", _
	"P̆", "p̆", "Ṕ", "ṕ", "P̌", "p̌", "Q̌", "q̌", "Q̧", "q̧", "Ŕ", "ŕ", "Ŗ", "ŗ", "Ř", "ř", "R̆", "r̆", "Ȓ", "ȓ", "Ȑ", "ȑ", "Ř̩", "ř̩", _
	"Ś", "ś", "Ŝ", "ŝ", "Ş", "Ș", "ș", "ş", "Š", "š", "ſ", "Ṥ", "ṥ", "Ṧ", "ṧ", "Ţ", "ţ", "ț", "Ț", "Ť", "ť", "Ŧ", "ŧ", "T̆", "t̆", "Þ", "þ", _
	"Ù", "Ú", "Û", "Ü", "Ủ", "Ụ", "Ử", "Ữ", "Ự", "ù", "ú", "û", "ü", "ủ", "ụ", "ử", "ữ", "ự", "Ũ", "ũ", "Ū", "ū", "Ŭ", "ŭ", _
	"Ů", "ů", "Ű", "ű", "Ų", "ų", "Ȗ", "ȗ", "Ư", "ư", "Ǔ", "ǔ", "Ǖ", "ǖ", "Ǘ", "ǘ", "Ǚ", "ǚ", "Ǜ", "ǜ", "Ứ", "ứ", "Ṹ", "ṹ", _
	"Ừ", "ừ", "Ȕ", "ȕ", "U̧", "u̧", "V̆", "v̆", "V̌", "v̌", "Ŵ", "ŵ", "Ẃ", "ẃ", "Ẁ", "ẁ", "W̌", "w̌", _
	"X̆", "x̆", "X́", "x́", "X̌", "x̌", "X̧", "x̧", "Ý", "ý", "ÿ", "Ŷ", "ŷ", "Ÿ", "Y̆", "y̆", "Ỳ", "ỳ", "Y̌", "y̌", _
	"Ź", "ź", "Ż", "ż", "Ž", "ž", "Z̧", "z̧", "Ѓ", "ѓ", "ё", "Ё", "й", "Й", "Ќ", "ќ")
	aTargetLetters = Array("A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", _
	"a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "A", "a", _
	"A", "a", "A", "a", "A", "a", "A", "a", "A", "a", "A", "a", "A", "a", "AE", "ae", "AE", "ae", _
	"B", "b", "B", "b", "C", "C", "c", "c", "C", "c", "C", "c", "C", "c", "C", "c", "C", "c", "C", "c", _
	"D", "d", "D", "d", "D", "d", "D", "d", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", _
	"e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "E", "e", "E", "e", "E", "e", "E", "e", _
	"E", "e", "E", "e", "E", "e", "E", "e", "E", "e", "E", "e", "f", "F", "f", _
	"G", "G", "g", "g", "G", "g", "G", "g", "G", "g", "G", "g", "H", "h", "H", "h", "H", "h", "H", "h", "H", "h", _
	"I", "I", "I", "I", "I", "I", "I", "I", "i", "i", "i", "i", "i", "i", "i", "i", "I", "i", "I", "i", "I", "i", "I", "i", "I", "i", "I", "i", "I", "i", "I", "i", "I", _
	"i", "I", "i", "IJ", "ij", "J", "j", "J", "j", "K", "k", "K", "k", "K", "k", "K", "k", "L", "l", "L", "l", "L", "l", "L", "l", "l", "l", _
	"M", "m", "M", "m", "M", "m", "M", "m", "N", "n", "N", "n", "N", "n", "N", "n", "n", "N", "n", "N", "n", _
	"O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", _
	"o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "O", "o", _
	"O", "o", "O", "o", "O", "o", "O", "o", "O", "o", "O", "o", "O", "o", "O", "o", "O", "o", "OE", "oe", _
	"P", "p", "P", "p", "P", "p", "Q", "q", "Q", "q", "R", "r", "R", "r", "R", "r", "R", "r", "R", "r", "R", "r", "R", "r", _
	"S", "s", "S", "s", "S", "S", "s", "s", "S", "s", "s", "S", "s", "S", "s", "T", "t", "t", "T", "T", "t", "T", "t", "T", "t", "TH", "th", _
	"U", "U", "U", "U", "U", "U", "U", "U", "U", "u", "u", "u", "u", "u", "u", "u", "u", "u", "U", "u", "U", "u", "U", "u", _
	"U", "u", "U", "u", "U", "u", "U", "u", "U", "u", "U", "u", "U", "u", "U", "u", "U", "u", "U", "u", "U", "u", "U", "u", _
	"U", "u", "U", "u", "U", "u", "V", "v", "V", "v", "W", "w", "W", "w", "W", "w", "W", "w", _
	"X", "x", "X", "x", "X", "x", "X", "x", "Y", "y", "y", "Y", "y", "Y", "Y", "y", "Y", "y", "Y", "y", _
	"Z", "z", "Z", "z", "Z", "z", "Z", "z", "Г", "г", "е", "Е", "и", "И", "К", "к")
	For i = LBound(aSourceLetters) To Ubound(aSourceLetters)
		If InStr(sString, aSourceLetters(i)) Then sString = Replace(sString, aSourceLetters(i), aTargetLetters(i))
	Next i
	RemoveAccent = sString
End Function 
1 Like

Gee I didn’t think asking a simple question would warrant a “calm down”, but life is full of surprises.

Nonetheless, that works much better, so thank you. Have still added a few more accented characters, but not nearly as many. There is one character that doesn’t want to behave - a type of p with a dash on top - which when I paste it into the macro section, just looks like a regular p. Otherwise it is good.

Do you mean (“post” or “after” in medicine)? Well, this is not the only exception. And not the last. :wink: