Reputation: 1
I'm trying to determine the length of a cell's comment but I get an object variable not set when there is no comment within the Cell.
Len(Range("C8").Comment.Text)
Upvotes: 0
Views: 201
Reputation: 12695
This happens because in that case Range("C8").Comment
is Nothing
, so the code fails when trying to retrieve the Text
property of Nothing
.
You need a null check:
If Not Range("C8").Comment Is Nothing Then
length = Len(Range("C8").Comment.Text)
End If
Upvotes: 1