Dynamic Notes?

PrettyGood_Not Great

Board Regular
Joined
Nov 24, 2023
Messages
101
Office Version
  1. 365
Platform
  1. Windows
Is is possible to have a note, dynamically populated? Could one perform a lookup with a cell reference and the result appear in a note?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
In my opinion. Notes cannot have formulas updated with the rest of the sheet. You can update notes using VBA. You could update them manually triggered or automatically by:
* Checking a cell or range change
* Sheet Activate or deactivate
* Selection change
* and others
 
Upvote 0
In my opinion. Notes cannot have formulas updated with the rest of the sheet. You can update notes using VBA. You could update them manually triggered or automatically by:
* Checking a cell or range change
* Sheet Activate or deactivate
* Selection change
* and others
I am not a strong VBA user, could you provide an example? I have a lookup table on a seperate sheet. The cells in question that are to contain the note/comment is the lookup value. The comment itself would be the return from the lookup table.

Ex. If this were an XLOOKUP.....=XLOOKUP(cell containing comment, lookup array, return array).
 
Upvote 0
Here goes. Ask many questions if needed. I created a button to update the Notes in a range of cells I called NotesRange. In each Note you need to add a line that looks like a formula that references another cell with the formula that gives you the results you want to display in the Note. In the Note for F7 on row 7 I put =O7. I put this on row 7 because I didn't want to show that when the user puts the mouse over the cell. The macro looks at each cell in the NotesRange and then finds the line where there is a Equals sign and interprets that as the cell you want to get. The macro replaces line 1 with the results of that cell and puts the rest of the lines back in also.

Create a button and call it UpdateNotes_Btn. Add the code below to the sheet module that the button resides


Book2
EFGHIJKLMNO
1Col1Col2
21$15,784.12
32$21,589.54
43$58,213.45
54$10,478.23
6
74$10,478.23
8
Sheet1
Cell Formulas
RangeFormula
O7O7=XLOOKUP(F7,L2:L5,M2:M5,"",0)
Named Ranges
NameRefers ToCells
NotesRange=Sheet1!$F$7:$F$11O7


1732556748024.png


Add this code to the SHEET Module
VBA Code:
Private Sub UpdateNotes_Btn_Click()
  Dim Cel As Range
  Dim aStr As String
  Dim LNS As Variant
  Dim X As Long
  Dim fStr As Variant
  
  For Each Cel In Range("NotesRange")
    aStr = ""
    fStr = ""
    On Error Resume Next
    aStr = Cel.Comment.Text
    On Error GoTo 0
    If aStr <> "" Then
      LNS = Split(aStr, Chr(10))
      For X = 0 To UBound(LNS)
        If Left(LNS(X), 1) = "=" Then
          fStr = Range(Mid(LNS(X), 2, 100)).Value
          'Debug.Print Cel.Comment.Shape.TextFrame.Characters(12, 1).Font.ColorIndex
          Exit For
        End If
      Next X
      If fStr <> "" Then
        LNS(0) = fStr
        aStr = ""
        For X = 0 To UBound(LNS)
          aStr = aStr & LNS(X)
          If X < UBound(LNS) Then aStr = aStr & Chr(10)
        Next X
        Cel.Comment.Delete
        Cel.AddComment
        Cel.Comment.Text Text:=aStr
      End If
    End If
  Next Cel
      
End Sub
 
Upvote 0
Here goes. Ask many questions if needed. I created a button to update the Notes in a range of cells I called NotesRange. In each Note you need to add a line that looks like a formula that references another cell with the formula that gives you the results you want to display in the Note. In the Note for F7 on row 7 I put =O7. I put this on row 7 because I didn't want to show that when the user puts the mouse over the cell. The macro looks at each cell in the NotesRange and then finds the line where there is a Equals sign and interprets that as the cell you want to get. The macro replaces line 1 with the results of that cell and puts the rest of the lines back in also.

Create a button and call it UpdateNotes_Btn. Add the code below to the sheet module that the button resides


Book2
EFGHIJKLMNO
1Col1Col2
21$15,784.12
32$21,589.54
43$58,213.45
54$10,478.23
6
74$10,478.23
8
Sheet1
Cell Formulas
RangeFormula
O7O7=XLOOKUP(F7,L2:L5,M2:M5,"",0)
Named Ranges
NameRefers ToCells
NotesRange=Sheet1!$F$7:$F$11O7


View attachment 119620

Add this code to the SHEET Module
VBA Code:
Private Sub UpdateNotes_Btn_Click()
  Dim Cel As Range
  Dim aStr As String
  Dim LNS As Variant
  Dim X As Long
  Dim fStr As Variant
 
  For Each Cel In Range("NotesRange")
    aStr = ""
    fStr = ""
    On Error Resume Next
    aStr = Cel.Comment.Text
    On Error GoTo 0
    If aStr <> "" Then
      LNS = Split(aStr, Chr(10))
      For X = 0 To UBound(LNS)
        If Left(LNS(X), 1) = "=" Then
          fStr = Range(Mid(LNS(X), 2, 100)).Value
          'Debug.Print Cel.Comment.Shape.TextFrame.Characters(12, 1).Font.ColorIndex
          Exit For
        End If
      Next X
      If fStr <> "" Then
        LNS(0) = fStr
        aStr = ""
        For X = 0 To UBound(LNS)
          aStr = aStr & LNS(X)
          If X < UBound(LNS) Then aStr = aStr & Chr(10)
        Next X
        Cel.Comment.Delete
        Cel.AddComment
        Cel.Comment.Text Text:=aStr
      End If
    End If
  Next Cel
   
End Sub

Thanks for this. I can see now that I was over complicating the matter. Because my lookup data is a header row generated by the same lookup table of interest, all of my values will always be in the correctly aligned order. The mini sheet below shows the problem I need to solve. Cell D7 should have a comment displaying "10", E7 with a comment displaying "11" and so on. Could you suggest a simplified solution to this?

The header row in practive is a TOROW(named range), with the lookup table on a separate sheet.

Book1
ABCDEFGHIJKL
1110
2211
3312
4413
5514
6615
771612345678
8817
9
10
Sheet1
 
Upvote 0
I need further explanation. Are you still on track trying to get Notes updated automatically? I don't see the issue on the mini sheet.
 
Upvote 0
I need further explanation. Are you still on track trying to get Notes updated automatically? I don't see the issue on the mini sheet.
The notes could be updated via button as you suggested, what's changed now is that I no longer need to perform an equation based lookup, at least not based on my original intention. Would I still use the VBA approach you've shown as is?
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,862
Members
452,676
Latest member
woodyp

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