This is the best I can come up with....I keep getting problems with it though...
Be careful with this because when you delete a value in a cell excel crashes...
I don't mean to give you a faulty code, but someone had to responde! AND maybe you (or anybody else) can see what's the matter with my code.
Take a look:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cmt As Comment
Dim keyword As Variant
Dim Ctr As Long
Dim loc As Long
Dim locComp As Long
Dim str As String
Dim CellFormula As String
Dim commFormula As String
keyword = Array("Formula")
For Each cmt In ActiveSheet.Comments
If cmt Is Nothing Then
'Do nothing
Else
For Ctr = LBound(keyword) To UBound(keyword)
str = cmt.Text
Do
loc = InStr(1, str, keyword(Ctr), vbTextCompare)
If loc > 0 Then
If cmt.Parent.HasFormula = True Then
CellFormula = cmt.Parent.Formula
commFormula = Mid(cmt.Text, 8, 15)
locComp = InStr(1, CellFormula, commFormula, vbTextCompare)
If locComp = 0 Then
cmt.Delete
cmt.Parent.AddComment Text:="Formula" & CellFormula
Else
'Do nothing
End If
Else
End If
Else
Exit Do
End If
Loop
Next Ctr
End If
Next cmt
End Sub
If you select the column that has the comment and insert a new column OR delete a previous column, it will ask you to debug. If you press End, you'll see the formula in the comment was replaced. But I can't get passed the errors!!!!
See if you can do anything with this. I hope I shed some light on your problem.