Automatically add cell contents of specific range to cell comments when opening a document

dslhs

New Member
Joined
Apr 4, 2022
Messages
48
Office Version
  1. 2019
Platform
  1. Windows
Hello,

Is there a way to automatically add cell contents of a specific range to cell comments on opening a document (specifically after the data from external sources has been updated).

The plan is to have a VBA code that:

- Wait till the document has been updated from linked documents (usually about 10 seconds)
- Takes the contents of each cell in H4:H100, I4:I100, J4:J100, K4:K100 and copies them into the comments for their respective cell
- Resize the comment box to fit around the text

The cells referenced don't contain the text themselves, but instead they reference other cells which contain a lot of text.

If you can get this to work, you'll make my staff and me very happy!

Many thanks,
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello,

Well it is technically possible, but i would not do it: it will be TERRIBLY SLOW. You have around 400 cells and for each of them you want to read the comment and edit it. The problem is that unlike other cells parameters (like the value) for which you can read and write in one go, the comments/notes need to be accessed cell by cell. We looked on another forum for the same kind of question and it was taking around 2min to run the macro for a smaller array… super slow.

What about simply coping the old values in other columns?
 
Upvote 0
Thanks for your response. Lots of those cells are blank - in fact, usually it will only be about 15 or so that will have any content. Is there a way of the system ignoring it if the cell contains nothing and thereby speeding up the process?
 
Upvote 0
Hello,

Well in this case it's very different !

Below a Sub you can call to update the given cells on the activesheet. However, I do not know which event will trigger this Sub (after what calculation?), maybe someone else can help you on this.

VBA Code:
Public Sub UpdateComments()
  Application.ScreenUpdating = False
 
  Dim cellsToUpdate As Range
  On Error Resume Next
  Set cellsToUpdate = ActiveSheet.Range("H4:K100").SpecialCells(xlCellTypeConstants)
  On Error GoTo 0
  If cellsToUpdate Is Nothing Then Exit Sub

  Dim currentCell   ' As Range
  For Each currentCell In cellsToUpdate
    With currentCell
      If .Comment Is Nothing Then
        .AddComment .Value2 & vbNullString
      Else
        .Comment.Text .Comment.Text & vbCrLf & .Value2
      End If
   
    .Comment.Shape.TextFrame.AutoSize = True
    End With
  Next currentCell
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,153
Members
452,615
Latest member
bogeys2birdies

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