Microsoft Office Tutorials and References
In Depth Information
Try It
4.
Using an If structure, evaluate the target cell for the existence of a comment. If there is no
comment, define the strText variable as “No comment.” For example:
If rng.Comment Is Nothing Then
strText = “No comment”
5.
Complete the If structure for the condition of the target cell containing a comment. For
example:
Else
strText = rng.Comment.Text
End If
6.
Set the name of the Function equal to the strText string expression. For example:
GetComment = strText
7.
Close the Function with the End Function statement. The entire UDF will look like this:
Function GetComment(rng As Range) As String
Dim strText As String
If rng.Comment Is Nothing Then
strText = “No comment”
Else
strText = rng.Comment.Text
End If
GetComment = strText
End Function
8.
Press Alt+Q to return to the worksheet, test your UDF to evaluate the existence of a
comment in cell A1, and return the conditional string with this formula:
=GetComment(A1)
To view the video that accompanies this lesson, please select Lesson 16, available
at the following website: www.wrox.com/go/excelvba .
Search JabSto ::




Custom Search