PC Review


Reply
Thread Tools Rate Thread

Adding comment to cells not working with merged cells

 
 
=?Utf-8?B?bWNwaGM=?=
Guest
Posts: n/a
 
      29th Aug 2007
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?
 
Reply With Quote
 
 
 
 
Bill Renaud
Guest
Posts: n/a
 
      29th Aug 2007
All other cells in a merged set of cells should be empty. Only the first
cell actually has data. Skip around setting the new value of the cell,
if it is empty.

If Not IsEmpty(cl) Then cl.Value = cl.Value & " : " & cmt.Text
--
Regards,
Bill Renaud



 
Reply With Quote
 
Bill Renaud
Guest
Posts: n/a
 
      29th Aug 2007
Correction (I forgot that the cell might be empty, but still have a
comment and not be merged):

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

If IsEmpty(cl) _
Then
cl.Value = " : " & cmt.Text
Else
cl.Value = cl.Value & " : " & cmt.Text
End If
Next cl

End Sub

Your code is crashing in the case where cl.Value is empty (merged or
not). You cannot concantenate an empty variable with a string to get
another string.
--
Regards,
Bill Renaud



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with pasting special merged cells to merged cells ritpg Microsoft Excel Programming 3 9th Mar 2010 07:14 PM
Adding Merged cells together =?Utf-8?B?QW1pZQ==?= Microsoft Excel Misc 2 21st Jun 2007 05:53 AM
Adding cells with a particular comment NC Microsoft Excel Discussion 4 18th Nov 2004 11:17 PM
adding comment to multiple cells andy Microsoft Excel Misc 1 13th Apr 2004 10:05 PM
Re: Adding a comment to a labeled set of cells Kalle Microsoft Excel Programming 0 16th Mar 2004 10:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:33 AM.