The following code inserts a comment with time, date, and cell value when a cell is changed. It works fine when the user presses Enter to enter the cell value, but if instead of pressing Enter the user selects a new cell the value is entered alright in the previous cell but the comment appears in the new cell. I hoped declaring rowInt and colInt as Static would cure this but it did not. So how can I assign values to rowInt and colInt so they do not change when the activecell is changed?
TIA
Sub InsertComment()
Static rowInt As Integer
Static colInt As Integer
Dim NumCells As Integer
Application.MoveAfterReturn = False
NumCells = Selection.Cells.Count
If NumCells 1 Then
MsgBox (“Macros only work with 1 cell selected”): Exit Sub
Else
rowInt = ActiveCell.Row
colInt = ActiveCell.Column
Application.ActiveSheet.Cells(rowInt, colInt).AddComment
Application.ActiveSheet.Cells(rowInt, colInt).Comment.Visible = True
Application.ActiveSheet.Cells(rowInt, colInt).Comment.Shape.Width = 250
Application.ActiveSheet.Cells(rowInt, colInt).Comment.Text “Comment inserted ” & Time & ” ” & Date _
& ” ” & Cells(rowInt, colInt).Value & Chr(10), 1, False
End If
End Sub