Awesome, both the hidden cell skipping and the Symbol font skipping seem to work just fine, and Japanese characters don’t seem to trigger any problems.
Turns out it wasn’t hidden cells that were the real problem though - it was formula. Skipping formula in hidden cells is already great, but if there’s a way to skip formula in unhidden cells too, please let me know!
Current code
Sub SymbolSubstitution()
Dim rng1, rng2, rng3 As Range
Dim newText As String
Application.ScreenUpdating = False
' Find range to search over.
Set rng1 = Cells.Find("*", [a1], xlFormulas, xlPart, xlByRows, xlPrevious)
Set rng2 = Cells.Find("*", [a1], xlFormulas, xlPart, xlByColumns, xlPrevious)
If Not rng1 Is Nothing Then
Set rng3 = Range([a1], Cells(rng1.Row, rng2.Column))
Else
MsgBox "Worksheet is empty", vbExclamation, "Error"
Exit Sub
End If
' Loop over cells in range.
For Each cell In rng3
' Skip hidden cells
If cell.EntireRow.Hidden = False And cell.EntireColumn.Hidden = False Then
' Only check non-empty cells.
If cell.Value <> "" Then
Call ConvertToSymbolAndReplace(cell, "Δ", "D")
Call ConvertToSymbolAndReplace(cell, "Φ", "F")
Call ConvertToSymbolAndReplace(cell, "Ω", "W")
Call ConvertToSymbolAndReplace(cell, "α", "a")
Call ConvertToSymbolAndReplace(cell, "β", "b")
Call ConvertToSymbolAndReplace(cell, "χ", "c")
Call ConvertToSymbolAndReplace(cell, "δ", "d")
Call ConvertToSymbolAndReplace(cell, "ε", "e")
Call ConvertToSymbolAndReplace(cell, "φ", "f")
Call ConvertToSymbolAndReplace(cell, "γ", "g")
Call ConvertToSymbolAndReplace(cell, "η", "h")
Call ConvertToSymbolAndReplace(cell, "ι", "i")
Call ConvertToSymbolAndReplace(cell, "φ", "j")
Call ConvertToSymbolAndReplace(cell, "κ", "k")
Call ConvertToSymbolAndReplace(cell, "λ", "l")
Call ConvertToSymbolAndReplace(cell, "μ", "m")
Call ConvertToSymbolAndReplace(cell, "ν", "n")
Call ConvertToSymbolAndReplace(cell, "ο", "o")
Call ConvertToSymbolAndReplace(cell, "π", "p")
Call ConvertToSymbolAndReplace(cell, "θ", "q")
Call ConvertToSymbolAndReplace(cell, "ρ", "r")
Call ConvertToSymbolAndReplace(cell, "σ", "s")
Call ConvertToSymbolAndReplace(cell, "τ", "t")
Call ConvertToSymbolAndReplace(cell, "υ", "u")
Call ConvertToSymbolAndReplace(cell, "ω", "w")
Call ConvertToSymbolAndReplace(cell, "ξ", "x")
Call ConvertToSymbolAndReplace(cell, "ψ", "y")
Call ConvertToSymbolAndReplace(cell, "ζ", "z")
Call ConvertToSymbolAndReplace(cell, "×", "´")
Call ConvertToSymbol(cell, "~")
Call ConvertToSymbol(cell, "&")
Call ConvertToSymbol(cell, "+")
Call ConvertToSymbol(cell, "%")
Call ConvertToSymbol(cell, "<")
Call ConvertToSymbol(cell, "=")
Call ConvertToSymbol(cell, ">")
Call ConvertToSymbol(cell, "°")
Call ConvertToSymbol(cell, "±")
Call ConvertToSymbolAndReplaceUnicode(cell, &H2219, &HD7) ' Small dot operator (must run after × to ´)
Call ConvertToSymbolAndReplaceUnicode(cell, &H2E31, &HD7) ' Small dot operator
Call ConvertToSymbolAndReplaceUnicode(cell, &HB7, &HD7) ' Small dot operator
Call ConvertToSymbolAndReplaceUnicode(cell, &H2027, &HD7) ' Small dot operator
Call ConvertToSymbolAndReplaceUnicode(cell, &H2022, &HB7) ' Large bullet (must run after HB7 to HD7)
Call ConvertToSymbolAndReplaceUnicode(cell, &H2211, &H53) ' Sum/sigma sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H2212, &H2D) ' Minus sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H2264, &HA3) ' Less than or equal sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H2265, &HB3) ' Greater than or equal sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H221A, &HD6) ' Square root sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H221E, &HA5) ' Infinity sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H222B, &HF2) ' Integral sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H2206, &H44) ' Alternative Delta sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H192, &HA6) ' Function sign
Call ConvertToSymbolAndReplaceUnicode(cell, &H3D5, &H66) ' Alternative phi
Call ConvertToSymbolAndReplaceUnicode(cell, &H3D6, &H76) ' Greek Pi
Call ConvertToSymbolAndReplaceUnicode(cell, &H251, &H61) ' Latin alpha
Call ConvertToSymbolAndReplaceUnicode(cell, &H25B, &H65) ' Latin epsilon
Call ConvertToSymbolAndReplaceUnicode(cell, &H269, &H69) ' Latin i
Call ConvertToSymbolAndReplaceUnicode(cell, &H275, &H71) ' Latin theta
Call ConvertToSymbolAndReplaceUnicode(cell, &H277, &H77) ' Latin omega
Call ConvertToSymbolAndReplaceUnicode(cell, &H278, &H66) ' Latin phi
Call ConvertToSymbolAndReplaceUnicode(cell, &H28B, &H75) ' Latin u
Call ConvertToSymbolAndReplaceUnicode(cell, &H2248, &HBB) ' Almost equal
Call ConvertToSymbolAndReplaceUnicode(cell, &H2260, &HB9) ' Not equal
Call ConvertToSymbolAndReplaceUnicode(cell, &H2261, &HBA) ' Indentical to
Call ConvertToSymbolAndReplaceUnicode(cell, &HF7, &HB8) ' Division sign
Call ConvertCelsius(cell, &H2103, &HB0, &H43) ' Celsius sign
End If
End If
Next cell
Application.ScreenUpdating = True
End Sub
Sub ConvertToSymbolAndReplace(ByRef thisCell As Variant, ByVal inputChar As String, ByVal outputChar As String)
Dim charPos As Long
charPos = InStr(thisCell.Value, inputChar)
Do While charPos > 0
If thisCell.Characters(charPos, 1).Font.Name <> "Symbol" Then ' Only execute code if font is not already Symbol.
thisCell.Characters(charPos, 1).Text = outputChar
thisCell.Characters(charPos, 1).Font.Name = "Symbol"
End If
charPos = InStr(charPos + 1, thisCell.Value, inputChar)
Loop
End Sub
Sub ConvertToSymbol(ByRef thisCell As Variant, ByVal inputChar As String)
Dim charPos As Long
charPos = InStr(thisCell.Value, inputChar)
Do While charPos > 0
thisCell.Characters(charPos, 1).Font.Name = "Symbol"
charPos = InStr(charPos + 1, thisCell.Value, inputChar)
Loop
End Sub
Sub ConvertToSymbolAndReplaceUnicode(ByRef thisCell As Variant, ByVal inputCharCode As Long, ByVal outputCharCode As Long)
Dim charPos As Long
charPos = InStr(thisCell.Value, ChrW(inputCharCode))
Do While charPos > 0
If thisCell.Characters(charPos, 1).Font.Name <> "Symbol" Then ' Only execute code if font is not already Symbol.
thisCell.Characters(charPos, 1).Text = ChrW(outputCharCode)
thisCell.Characters(charPos, 1).Font.Name = "Symbol"
End If
charPos = InStr(charPos + 1, thisCell.Value, ChrW(inputCharCode))
Loop
End Sub
Sub ConvertCelsius(ByRef thisCell As Variant, ByVal inputCharCode As Long, ByVal outputCharCode As Long, ByVal outputCharCode2 As Long)
Dim charPos As Long
charPos = InStr(thisCell.Value, ChrW(inputCharCode))
Do While charPos > 0
thisCell.Characters(charPos, 1).Text = ChrW(outputCharCode)
thisCell.Characters(charPos, 1).Font.Name = "Symbol"
charPos = charPos + 1
thisCell.Characters(charPos, 1).Text = ChrW(outputCharCode2)
thisCell.Characters(charPos, 1).Font.Name = "Times New Roman"
charPos = InStr(charPos + 1, thisCell.Value, ChrW(inputCharCode))
Loop
End Sub