How can I remove Range.PrefixCharacter from a cell without removing all of its formatting? Note that Range.PrefixCharacter is readonly.
VBA Code:
Sub Test()
Dim cell As Range
Set cell = Range("$A$1")
'Set some example formatting that we ideally don't want to be removed
cell.Font.Bold = True
cell.Interior.Color = RGB(255, 0, 0)
'Set initial cell value including prefix character
cell.Value = "'abc"
Call SetNewCellValue(cell, "def", False)
'Call SetNewCellValue(cell, "def", True)
If cell.PrefixCharacter = "'" Then
MsgBox "Cell still has PrefixCharacter"
End If
End Sub
Sub SetNewCellValue(cell As Range, newValue As Variant, clearFormats As Boolean)
If clearFormats Then
'This will clear cell.PrefixCharacter but will also remove all other cell formatting
cell.clearFormats
End If
cell.Value = newValue
End Sub