I am trying to write a UDF to add a note to the cell it is in. Here's the code I have:
The goal is to select a cell with the text I want in the note for variable 1, and select the cell above the cell comcopy is entered in so the note is generated in that cell.
However, when I first enter the function, I get a value error. Then, if I delete the "Comment.Delete" line it all works fine. Then, if I put the "Comment.Delete" line back in it works fine. However, if I put the function in another cell I have to do the whole process of deleting the line over again to get it to work there.
Is there a way to fix this code or is there a better way to do this?
Thanks!
VBA Code:
Function comcopy(cll2 As Range, cll As Range) As Integer
Dim c As Integer
Dim r As Integer
c = cll.Column
r = cll.Row + 1
comcopy = 0
Sheet7.Cells(r, c).Comment.Delete
Sheet7.Cells(r, c).AddComment (cll2.Text)
End Function
The goal is to select a cell with the text I want in the note for variable 1, and select the cell above the cell comcopy is entered in so the note is generated in that cell.
However, when I first enter the function, I get a value error. Then, if I delete the "Comment.Delete" line it all works fine. Then, if I put the "Comment.Delete" line back in it works fine. However, if I put the function in another cell I have to do the whole process of deleting the line over again to get it to work there.
Is there a way to fix this code or is there a better way to do this?
Thanks!