How to Extract Comments in Excel (3 Suitable Examples)

To illustrate how to extract comments in Excel, we’ll use a sample dataset with 4 comments in the range of cells C4:C8.

The VBA module is available in the Developer tab. If you don’t have the tab in your Excel ribbon, you have to enable the Developer tab from the Excel options.


Method 1 – Extracting Comments Using User Defined Function

Steps:

  • In the Developer tab, click on Visual Basic. The shortcut key to open the Visual Basic Editor is ‘Alt+F11’.

Note: If the Developer tab is not in your Excel ribbon, you have to enable it from Excel options.

Extracting Comments Using User Defined Function

  • In the Insert tab on the dialog box, click Module.

Extracting Comments Using User Defined Function

  • In the editor box, enter the following visual code.

Function Extract_Comments(xCell As Range) As String
On Error Resume Next
Extract_Comments = xCell.Comment.Text
End Function
  • Press ‘Ctrl+S’ to save the code.
  • Close the Editor
  • In cell E5, enter the following formula:

=Extract_Comments(C5)

  • Press Enter.

Extracting Comments Using User Defined Function

  • Drag the Fill Handle icon to cell E8.

Extracting Comments Using User Defined Function

Read More: How to Extract Comments in Excel


Method 2 – Using Add-ins and Applying VBA Macro to Extract Comments

Steps:

  • In the Developer tab, click on Visual Basic.

Embedding VBA Code

  • In the Insert tab on the dialog box, click Module.

Extracting Comments Using User Defined Function

  • Enter the following visual code in the editor box.

Sub Extract_Cell_Comments()
Dim Extract_Comment As Comment
Dim x As Integer
Dim work_sheet As Worksheet
Dim C_S As Worksheet
Set C_S = ActiveSheet
If ActiveSheet.Comments.Count = 0 Then Exit Sub

For Each work_sheet In Worksheets
  If work_sheet.Name = "Comments" Then x = 1
Next work_sheet
    
If x = 0 Then
  Set work_sheet = Worksheets.Add(After:=ActiveSheet)
  work_sheet.Name = "Comments"
Else: Set work_sheet = Worksheets("Comments")
End If

For Each Extract_Comment In C_S.Comments
  work_sheet.Range("B4").Value = "Reference"
  work_sheet.Range("C4").Value = "Author"
  work_sheet.Range("D4").Value = "Comment"
  With work_sheet.Range("B4:D4")
    .Font.Bold = True
    .Font.Color = RGB(255, 255, 255)
    .Interior.Color = RGB(32, 55, 100)
    .Rows.RowHeight = 20
  End With
  If work_sheet.Range("B5") = "" Then
    work_sheet.Range("B5").Value = Extract_Comment.Parent.Address
    work_sheet.Range("C5").Value = Left(Extract_Comment.Text, InStr _
    (1, Extract_Comment.Text, ":") - 1)
    work_sheet.Range("D5").Value = Right(Extract_Comment.Text, Len(Extract_Comment.Text) _
    - InStr(1, Extract_Comment.Text, ":"))
  Else
    work_sheet.Range("B4").End(xlDown).Offset(1, 0) = Extract_Comment.Parent.Address
    work_sheet.Range("C4").End(xlDown).Offset(1, 0) = Left(Extract_Comment.Text, _
    InStr(1, Extract_Comment.Text, ":") - 1)
    work_sheet.Range("D4").End(xlDown).Offset(1, 0) = Right(Extract_Comment.Text, _
    Len(Extract_Comment.Text) - InStr(1, Extract_Comment.Text, ":"))
  End If
Next Extract_Comment
End Sub
  • Press ‘Ctrl+S’ to save the code in that module.
  • Close the Editor
  • Click on File > Save As.
  • Rename for your file and choose the file format as .xlam. For this file, we will set the name as Extract Comments.
  • Save the file in your desired location. In this case, we will save it on the Desktop.

  • Go to the Developer tab and select the Excel Add-ins option from the Add-ins group.

Using Add-ins and Applying VBA Macro to Extract Cell Comments

  • You may not find the name of the add-ins as we didn’t save it at the built-in location. To get it, click on the Browse option.

  • Go to the location where you have saved the file.
  • Select the file and click OK.

  • Check the Extract Comments and click OK. The add-ins will be added.

Using Add-ins and Applying VBA Macro to Extract Cell Comments

  • In the Developer tab, click on Macros.

Using Add-ins and Applying VBA Macro to Extract Cell Comments

  • Select Extract_Cell_Comments.

Using Add-ins and Applying VBA Macro to Extract Cell Comments

  • Click on the Run button to run this code.
  • A new sheet named Comments will be created in the Sheet Bar and in that sheet, the comments are extracted. Format the cell range according to your needs.

Using Add-ins and Applying VBA Macro to Extract Cell Comments


Method 3 – Extracting Comments to New Worksheet

Steps:

  • Go to the Developer tab and click on Visual Basic.

Embedding VBA Code

  • In the Insert tab on the dialog box, click on the Module.

Extracting Comments Using User Defined Function

  • Enter following VBA code.

Sub Extract_All_Comments()

Dim wrk_sheet As Worksheet
Dim comm_list As Comment
Dim cal As Long

cal = 0

For Each wrk_sheet In ActiveWorkbook.Worksheets
    For Each comm_list In wrk_sheet.Comments
        Worksheets("Result").Range("B5").Offset(cal, 0).Parent.Hyperlinks.Add _
            Anchor:=Worksheets("Result").Range("B5").Offset(cal, 0), _
            Address:="", _
            SubAddress:="'" & wrk_sheet.Name & "'!" & comm_list.Parent.Address, _
            TextToDisplay:="'" & wrk_sheet.Name & "'!" & comm_list.Parent.Address
        Worksheets("Result").Range("C5").Offset(cal, 0).Value = comm_list.Author
        Worksheets("Result").Range("D5").Offset(cal, 0).Value = comm_list.Text
        cal = cal + 1
    Next comm_list
Next wrk_sheet

End Sub
  • Press ‘Ctrl+S’ to save the code.
  • Close the Editor
  • Click on the Plus sign in the Sheet Bar and rename it as Result.

  • Go to the Developer tab and click on Macros.

Using Add-ins and Applying VBA Macro to Extract Cell Comments

  • Select Extract_All_Comments.
  • Click on the Run button to run this code.

Extracting Cell Comments to a New Worksheet in Excel

  • The comments will be extracted in the sheet named Result. Format the cells if you require any specific cell formatting.

Extracting Cell Comments to a New Worksheet in Excel

Read More: Convert Comments to Notes in Excel 


Download Practice Workbook


Related Articles


<< Go Back to Comments in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Soumik Dutta
Soumik Dutta

Soumik Dutta, having earned a BSc in Naval Architecture & Engineering from Bangladesh University of Engineering and Technology, plays a key role as an Excel & VBA Content Developer at ExcelDemy. Driven by a profound passion for research and innovation, he actively immerses himself in Excel. In his role, Soumik not only skillfully addresses complex challenges but also demonstrates enthusiasm and expertise in gracefully navigating tough situations, underscoring his unwavering commitment to consistently deliver exceptional, high-quality content that... Read Full Bio

2 Comments
  1. Hello
    Thank you for the vba code for extracting comments to a new sheet.
    How would I change the code to have the cell value be displayed instead of the
    author.
    instead of ‘outputting” Asus for all comments extracted it would say
    “NY to Philadelphia”
    thanks for any feedback

    • Thank you Dave for your query. In order to replace the Author with Cell value, in the Extract_All_Comments subroutine, you can replace the following line :

      
      Worksheets("Result").Range("C5").Offset(cal, 0).Value = comm_list.Author
      

      with this line:

      Worksheets("Result").Range("C5").Offset(cal, 0).Value = wrk_sheet.Range(comm_list.Parent.Address).Value 

      So the final code will be as below:

      
      Sub Extract_All_Comments()
      
      Dim wrk_sheet As Worksheet
      Dim comm_list As Comment
      Dim cal As Long
      
      cal = 0
      
      For Each wrk_sheet In ActiveWorkbook.Worksheets
          For Each comm_list In wrk_sheet.Comments
              Worksheets("Result").Range("B5").Offset(cal, 0).Parent.Hyperlinks.Add _
                  Anchor:=Worksheets("Result").Range("B5").Offset(cal, 0), _
                  Address:="", _
                  SubAddress:="'" & wrk_sheet.Name & "'!" & comm_list.Parent.Address, _
                  TextToDisplay:="'" & wrk_sheet.Name & "'!" & comm_list.Parent.Address
              Worksheets("Result").Range("C5").Offset(cal, 0).Value = wrk_sheet.Range(comm_list.Parent.Address).Value
              Worksheets("Result").Range("D5").Offset(cal, 0).Value = comm_list.Text
              cal = cal + 1
          Next comm_list
      Next wrk_sheet
      End Sub
      

      Hope, it will solve your problem.
      Regards
      Aniruddah
      Exceldemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo