Excel - convert columns to comments
Posted on December 10, 2021 (Last modified on October 23, 2024) • 1 min read • 204 wordsSituation: You have table rows containing short headings, and the cell next to it a long text description. You want to “convert” the description column into comments on the “heading” cells to make the table smaller or save vertical space. Maybe a two images explain that better.
So we want to go from “before” …
… to “after” …
Now this is the Excel VBA code to achieve this:
Sub convert_to_comment()
' convert_to_comment Makro
' Tastenkombination: Strg+k
' step 1 - create (VISIBLE!) comments
' visible because excel has a bug. yeah ... .
Dim commentText As String
ActiveCell.Comment.Delete
commentText = ActiveCell.Offset(0, 1).Text
ActiveCell.AddComment commentText
ActiveCell.Comment.Visible = True
ActiveCell.Comment.Shape.Width = 450
ActiveCell.Comment.Shape.Height = 150
ActiveCell.Offset(1, 0).Select
' make comments invisible in step 2
' just comment all lines from step1, and uncomment all of the following
' lines, and re-run the macro with each cell. see notes below in the
' blog post.
'ActiveCell.Comment.Visible = False
'ActiveCell.Offset(1, 0).Select
End Sub
Some notes: