How do I determine if activesheet.Cells(1,1) has an associated comment object?
I am creating a process that will copy formulas from all cells on a worksheet and paste that formula into the comment for that cell.
****CODE
Const conEscapeString = "~~"
Public Sub CaptureFormulas(wks As Worksheet, lngRows As Long, lngCols As Long)
Dim lngRow As Long
Dim lngCol As Long
Dim strOrigCmnt As String
Dim strNewCmnt As String
For lngRow = 1 To lngRows
For lngCol = 1 To lngCols
If wks.Cells(lngRow, lngCol).Formula Like "=*" Then
strNewCmnt = conEscapeString & wks.Cells(lngRow, lngCol).Formula
[red]if <comment exists> then[/red]
strOrigcmnt=wks.cells(lngRow,lngCol).comment.text
wks.Cells(lngRow, lngCol).Comment.Text Text:= strorigcmnt & chr(13) & strnewcmnt
Else
wks.Cells(lngRow, lngCol).AddComment strNewCmnt
End If
End If
Next lngCol
Next lngRow
End Sub
**** END CODE
The red section is where I need a way to distinguish if a comment already exist for the that and I need to change the text property of the comment, or if it does not exist and I need to use the addcomment method.
I am creating a process that will copy formulas from all cells on a worksheet and paste that formula into the comment for that cell.
****CODE
Const conEscapeString = "~~"
Public Sub CaptureFormulas(wks As Worksheet, lngRows As Long, lngCols As Long)
Dim lngRow As Long
Dim lngCol As Long
Dim strOrigCmnt As String
Dim strNewCmnt As String
For lngRow = 1 To lngRows
For lngCol = 1 To lngCols
If wks.Cells(lngRow, lngCol).Formula Like "=*" Then
strNewCmnt = conEscapeString & wks.Cells(lngRow, lngCol).Formula
[red]if <comment exists> then[/red]
strOrigcmnt=wks.cells(lngRow,lngCol).comment.text
wks.Cells(lngRow, lngCol).Comment.Text Text:= strorigcmnt & chr(13) & strnewcmnt
Else
wks.Cells(lngRow, lngCol).AddComment strNewCmnt
End If
End If
Next lngCol
Next lngRow
End Sub
**** END CODE
The red section is where I need a way to distinguish if a comment already exist for the that and I need to change the text property of the comment, or if it does not exist and I need to use the addcomment method.