In this article, you will learn how to create a User-defined function in VBA to get the comment text from an Excel Cell. Let’s say we have attendance data on the Excel sheet and We are putting comments for the absent employees. Now if we need to fetch these comments in Excel cell to do some analysis then we can use this UDF.
Below is the code for this User-defined function.
Option Explicit Function Get_Comments(rng As Range) As String Application.Volatile Get_Comments = rng.Comment.Text 'Remove user name If InStr(Get_Comments, ":" & Chr(10)) > 0 Then Get_Comments = Right(Get_Comments, Len(Get_Comments) - VBA.InStr(Get_Comments, ":" & Chr(10)) - 1) End If End Function