It occurred to me it would be usefull to be able to "comment out" cells in a spreadsheet, the same way one can comment lines of code. So I wrote a couple of subs to do it. See below:
Commenting out the cells works fine. Unfortunately, the reverse operation does not work, because, even when they are there, apostrophes do not seem to be recognised as part of a cell's formula.
Does anyone know what cell property which actually gives the true contents, including any apostrophes?
Tony
Code:
Public Sub Comment_out()
Dim rng As Range
Dim mode As Variant
mode = Application.Calculation
Application.Calculation = xlCalculationManual
For Each rng In Selection
rng.Formula = "'" & rng.Formula
Next rng
Application.Calculation = mode
End Sub
Public Sub Undo_Comment_out()
Dim rng As Range
Dim mode As Variant
mode = Application.Calculation
Application.Calculation = xlCalculationManual
For Each rng In Selection
If Mid(rng.Formula, 1, 1) = "'" Then rng.Formula = Mid(rng.Formula, 2, Len(rng.Formula - 1))
Next rng
Application.Calculation = mode
End Sub
Commenting out the cells works fine. Unfortunately, the reverse operation does not work, because, even when they are there, apostrophes do not seem to be recognised as part of a cell's formula.
Does anyone know what cell property which actually gives the true contents, including any apostrophes?
Tony