How to insert the formula result in Excel comment?


In this article, users will learn how to insert the formula result in Excel comments. The two different ways to achieve the same task. The first example, allows the user to use the VBA code, to show the formula result as a comment in Excel. After that the next task allows the user to insert the result as a comment in the Excel sheet by using the kutools. All the provided steps are clear and precise. Details provided within all the steps are detailed and thorough.

Example 1: To use VBA code to insert the formula result in Excel as a comment.

Step 1

To understand the process of inserting formula results as comments in the Excel sheet, consider an Excel spreadsheet. This spreadsheet contains a few columns, such as emp code, salary, bonus, and total. It is important to note that the value of the total column stores the sum of salary and bonus values. A snapshot for the Excel sheet is provided below:

Step 2

Here the user will perform the task by using the VBA code. For this user need to open the VBA editor. To do so, right−click on the sheet tab. This will display a list of options, among the available list of options select the “View Code” option. A snapshot for the same is provided below:

Step 3

The other dialog box “Microsoft Visual Basic for Applications” will open. This dialog box displays a large empty code area. A snapshot of the same is given below:

Step 4

Copy the below provided code to editor:

'define module Sub add_comment_to_formula() 'declare required variable Dim range_x As Range Dim text_x As String Dim cell_x As Range On Error Resume Next 'if salary If ActiveWindow.RangeSelection.Count > 1 Then ' setting variables text_x = ActiveWindow.RangeSelection.AddressLocal 'else statement Else ' setting variables text_x = ActiveSheet.UsedRange.AddressLocal ' end of if block End If ' setting range variable Set range_x = Application.InputBox("Set the certain cell:", "Formula result", text_x, , , , , 8) ' if range is nothing If range_x Is Nothing Then Exit Sub ' on error resume next On Error Resume Next Application.ScreenUpdating = False ' for each loop For Each cell_x In range_x ' if cell has formula If cell_x.HasFormula Then 'calling delete cell_x.Comment.Delete ' calling add comment cell_x.AddComment CStr(cell_x.Value) 'end of if statement End If ' next statement Next ' screen update to true Application.ScreenUpdating = True End Sub

After typing or pasting the above code into the code area, click on the “Run” button. A snapshot for the same is given below:

Step 5

The run option will display the “Kutools for Excel” dialog box. In the input area, select the rows, and then click on the “OK” button.

Step 6

The above step will add a comment to the total column. This column contains comments that store the sum data. Snapshot for the same is provided below:

Example 2: To insert the formula result in Excel in the comments by using the kutools.

Step 1

For this example, will be using the same Excel sheet. A snapshot of the same is provided below:

Step 2

After that go to the “kutools” tab, further go to the “Editing” tab, then select the “More” tile, and further select the option, “Convert Comment and Cell…”. For proper reference consider the below-provided snapshot of data:

Step 3

The above step will open a “Convert Comment and Cell” dialog box. This dialog box allows the user to select the data range in the source range label, and then under the convert label, select the second option “Insert content of cell into comments”, and finally click on the “OK” button.

Step 4

The above step will again add the comment label to the total column. Snapshot for the same is provided below:

Conclusion

This article guides the user through the process of inserting the result generated by a formula as a comment to the last column. Two examples are depicted in this article. Users must write the proper syntax and declarations, and statements in the VBA code to obtain the desired result. All the provided steps are detailed and thorough.

Updated on: 25-Jul-2023

194 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements