It can sometimes be helpful having a large cell value in a comment. You can then easily hover over cell and read the value instead of resizing column widths.
How to run macro?
Press Alt + F8 to open the Macro dialog box.
Click on macro Createcomments to select it.
Click "Run" button to execute the selected macro.
An input box shows up on your screen asking for a cell range that you want to apply comments to.
Only cells containing values that don't fit will get a comment.
Click OK button.
The macro adds comments.
The macro ends.
The animated image below shows what happens when you run macro Createcomments.
The following subroutine adds a comment to cells where the value exceeds the column width.
'Dimension variables and declare data types
Dim rng As Range
Dim Cell As Variant
'Enable error handling
On Error Resume Next
'Show inputbox and save input value to object variable rng
Set rng = Application.InputBox(Prompt:="Select a range:", _
Title:="Create comments in cells where the value is larger than column width", _
'Disable error handling
On Error GoTo 0
'Check if variable rang is empty
If rng Is Nothing Then
'Continue if variable rng is not empty
'Iterate through cells in object rng
For Each Cell In rng
'Check if characters in cell value is wider than column width
If Len(Cell) * 0.9 > Cell.ColumnWidth Then
'Check that there is no comment to prevent overwriting older comments
If Cell.Comment Is Nothing Then
'Add value to cell comment
Where to put the code?
Copy above VBA code.
Press Alt+F11 to open the VB Editor.
Select your workbook in the Project Explorer.
Click on "Insert" on the menu.
Click on "Module" to insert a code module to your workbook.
Paste VBA code to code module.
Exit VB Editor and return to Excel.
Note, save your workbook with file extension *.xlsm in order to keep the code to your workbook. If not, the code will be gone the next time you open up the same workbook.