M
mcphc
I have some code that adds a cells comments to the cell value as below:
Sub CommentsToCells()
Dim cl As Range
Dim rng As Range
Dim cmt As Comment
On Error Resume Next
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeComments)
On Error GoTo 0
For Each cl In rng
Set cmt = cl.Comment
cl.Value = cl.Value & " : " & cmt.text
Next cl
End Sub
This works well with unmerged cells but when the cells are merged the cell
value is updated but then the code stops with the error:
Run-time error '91':
Object variable or With block variable not set
How can I get this to work for merged cells as well?
Sub CommentsToCells()
Dim cl As Range
Dim rng As Range
Dim cmt As Comment
On Error Resume Next
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeComments)
On Error GoTo 0
For Each cl In rng
Set cmt = cl.Comment
cl.Value = cl.Value & " : " & cmt.text
Next cl
End Sub
This works well with unmerged cells but when the cells are merged the cell
value is updated but then the code stops with the error:
Run-time error '91':
Object variable or With block variable not set
How can I get this to work for merged cells as well?