Its purpose is to result in a "zero value" calculated by
retaining the original expression in the cell, enclosed by
a parenthesis and multiplied by zero
What about something like this (works on all cells within a selection)....
Sub PreserveSelectedCells()
Dim CellInSelection As Range
For Each CellInSelection In Selection
With CellInSelection
If Len(.Formula) > 0 Then
If Left(.Formula, 1) = "=" Then
.Formula = Replace(.Formula, "=", "=N(", , 1) & ")*0"
Else
.Formula = "=N(""@" & .Formula & """)*0"
End If
End If
End With
Next
End Sub
Note the use of the N function so that the cell's evaluated content can be
numeric or text. In the case of a cell containing either a numeric constant
or text constant (that is, without a leading equal sign), an equal sign,
followed by the N function "housing" followed by a quote mark followed by
and @ symbol are prefixed to it and a quote mark followed by the N
function's closing parenthesis and then followed by the multiplication by
zero characters. This is done so the following subroutine will be able to
recognize the non-formula entry and take appropriate steps to be able to
reverse it. The down side to the above is a pure text entry ends up as a
numeric zero while it is "preserved".
The following subroutine can be used to restore the cell to its original
content and/or formula...
Sub RestoreSelectedCells()
Dim CellInSelection As Range
For Each CellInSelection In Selection
With CellInSelection
If .Formula Like "=N(""@*"")*0" Then
.Formula = Mid(.Formula, 6, Len(.Formula) - 9)
ElseIf .Formula Like "=N(*)*0" Then
.Formula = Replace("=" & Mid(.Formula, 4, _
Len(.Formula) - 6), "=#@", "")
End If
End With
Next
End Sub
Rick