Cannot reliably predict whether Excel will treat cell as a string or formula when I have a string: '=Sum(A1:A4) [say]
...and proceed to Search/Replace '=Sum with =Sum;
Sometimes will evaluate and sometimes will not.
>>My VBA solution is as follows -
but I would like to know a native Excel solution (if it exists).
'-----
Sub Toggle_Formula()
Dim oCell As Range
'This sub will toggle a cell between string/formula
'Sometimes you can achieve this with a search replace...sometimes not
'...and I cannot determine exactly when or why this Excel behaviour changes.
'Hence this function - which seems to work as required.
For Each oCell In Selection
If oCell.Formula = oCell Then
'Note this expression will force Excel to evaluate!!
'=============================
oCell.Formula = oCell.Formula
'=============================
Else
oCell.Formula = "'" & oCell.Formula
End If
Next oCell
End Sub
Bookmarks