Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[Ctrl+C]
[ALT,E,S,V]
Sub CommentFormula()
' v1.0 - 2001.06.12 - LoNeRaVeR
Dim bEqual As Boolean
Dim iEqual As Integer
Dim iLen As Integer
Dim iLoc As Integer
Dim sAuthor As String
Dim sComment As String
Dim sCR As String
Dim sCR2 As String
Dim sDate As String
Dim sFormula As String
Dim sResponse As String
Dim sTime As String
bEqual = False
sAuthor = Application.UserName
sCR = Chr(10)
sCR2 = sCR & sCR
sDate = Format(Date, "yyyy.mm.dd")
sTime = Format(Time, "hh:mm")
sFormula = ActiveCell.Formula
iLen = Len(sFormula)
For iEqual = 1 To iLen
If Mid(sFormula, iEqual, 1) = "=" Then bEqual = True
Next iEqual
If bEqual = False Then sFormula = ActiveCell.Value
With ActiveCell
On Error GoTo ErrorHandler:
.AddComment
.Comment.Text Text:=sAuthor & sCR & sDate & _
" " & sTime & sCR2 & sFormula
.Comment.Visible = False
End With
Exit Sub
ErrorHandler:
sResponse = MsgBox(Prompt:="Copy Formula from Comment to Cell?", _
Buttons:=vbYesNo, Title:="Comment Formula")
If sResponse = vbYes Then
sComment = ActiveCell.Comment.Text
iLen = Len(sComment)
If bEqual = False Then
iLoc = Application.WorksheetFunction.Find(sCR2, sComment, 1)
sFormula = Right(sComment, iLen - iLoc - 1)
ActiveCell.Value = sFormula
Resume Next
End If
iLoc = Application.WorksheetFunction.Find("=", sComment, 1)
sFormula = Right(sComment, iLen - iLoc + 1)
ActiveCell.Formula = sFormula
End If
If sResponse = vbNo Then
sResponse = MsgBox(Prompt:="Overwrite Comment with Cell Formula?", _
Buttons:=vbYesNo, Title:="Comment Formula")
If sResponse = vbYes And bEqual = False Then
sFormula = ActiveCell.Value
ActiveCell.Comment.Delete
ActiveCell.AddComment
ElseIf sResponse = vbNo Then
sResponse = MsgBox(Prompt:=" Erase Comment?", _
Buttons:=vbYesNo, Title:="Comment Formula")
If sResponse = vbYes Then ActiveCell.Comment.Delete
Exit Sub
End If
End If
Resume Next
End Sub