I have a spreadsheet that contains emojis, e.g., , and I am looking for a solution to use Excel VBA to replace the emojis with null.
Emojis can be removed using the Excel replace action, so I recorded a macro to automate the replace. I opened the recorded macro and it was displayed as follows:
Sub Remove_Emojis()
Cells.Replace What:="??", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
End Sub
The problem is that VBA doesn't recognize emojis () and replaces them with "??", i.e., Unicode characters above a certain value are not recognized by VBA.
I tried replacing "??" with ChrW()
:
Sub Remove_Emojis()
Cells.Replace What:=ChrW(128515), Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
End Sub
but this results in an error:
Invalid procedure call of argument
because the ChrW() function does not allow a value above 65535. Note: The ChrW() function works if the value of the argument is within the range -32,767 to 65,535.
I expect that there should be support for doing this in VBA given that it can be done in Excel.