Die Excel/VBA-Beispiele (incl. aller Arbeitsmappen: http://www.herber.de/samples/inhalt.html)

Anzeige der Formel mit Quellblattangabe

Problem: Im Kommentar soll das mit dem Zellinhalt verknüpfte Tabellenblatt genannt werden.


ClassModule: Tabelle1

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
   Dim cmt As Comment
   Dim sTxt As String
   If Target.Cells.Count > 1 Then Exit Sub
   If IsEmpty(Target) Then Exit Sub
   Application.DisplayCommentIndicator = xlCommentIndicatorOnly
   If Not Target.Comment Is Nothing Then
      Target.Comment.Delete
   End If
   If Target.HasFormula Then
      If InStr(Target.Formula, "!") > 0 Then
         sTxt = Left(Target.Formula, InStr(Target.Formula, "!") - 1)
         Set cmt = Target.AddComment(sTxt)
         cmt.Shape.TextFrame.AutoSize = True
      End If
   End If
End Sub