I am trying to move comments 3 columns to the right and then delete the comment from the source cell.
The following code works to do that if the cell that is referenced by range r2 contains a comment.
If the cell does not contain a comment, the very first time through the 'i' loop when the statement
is hit, the code will jump to the label nocom: (which is the behavior that i desire). However, the next time through the i loop, the code hits that statement and does not jump to the label nocom:. Instead it gives the message Run timeError 91, "Object variable or With block variable not set". Why does it do the jump one and only one time? Suggestions for how can this be accomplished? Thank you.
The following code works to do that if the cell that is referenced by range r2 contains a comment.
If the cell does not contain a comment, the very first time through the 'i' loop when the statement
VBA Code:
txt = r2.Comment.Text
VBA Code:
Sub Move_Comment()
Dim r As Range
Dim r2 As Range
Dim txt As String
comoffset = 3
Set r = Range("BK12")
For i = 0 To -24 Step -1
Set r2 = Range(r.Offset(0, i).Address)
On Error GoTo nocom
txt = r2.Comment.Text
r2.Offset(0, comoffset).AddComment
r2.Offset(0, comoffset).Comment.Text Text:=txt
r2.ClearComments
nocom:
txt = ""
Next i
End Sub