Function in Comment - Possible ?

kenstr

New Member
Joined
Mar 19, 2002
Messages
11
Is it possible to have a function in a cell comment ?

Say something like " =$c$4 "

Thanks,

Ken
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi Ken,

No, a comment can't evaluate a formula. However a simple VBA event macro can accomplish the same thing. For example, the code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$B$4" Then
Target.Comment.Shape.TextFrame.Characters.Text = [c4].Text
End If
End Sub

will update the comment in cell B4 to contain whatever is displayed in cell C4 whenever cell B4 is selected (it must be selected--not just a mouseover). In addition, the cell B4 must already contain a comment since this code just modifies the existing comment.

This code must be inserted in the worksheet's event code module. To do this, right-click on the worksheet's tab, select View Code, and insert the code in the code pane.

Damon
 
Upvote 0
Thanks Juan Pablo,

Yes, Dave Hager's solution is a very interesting one. I'm not sure I would officially say that the comment is calculating the formula since it requires VBA to evaluate it and return the value, but it appears to work as if it were, except that it apparently doesn't recognize dependencies.

I keep forgetting the power of the Evaluate function!

Damon
 
Upvote 0

Forum statistics

Threads
1,221,695
Messages
6,161,361
Members
451,699
Latest member
sfairbro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top