PDA

View Full Version : Solved:Error when no comments found



zoom38
10-15-2007, 06:09 PM
I have another issue with comments. I have the following code in a Worksheet change event for formatting comments.


Dim cell As Range

For Each cell In Cells.SpecialCells(xlCellTypeComments)
With cell.Comment.Shape.TextFrame
.Characters.Font.Name = "Tahoma"
.Characters.Font.Size = 14
.Characters.Font.Bold = True
.Characters.Font.ColorIndex = 1 'Black
.AutoSize = True
End With
cell.Comment.Shape.TextFrame.AutoSize = True
Next cell


It works great except if there are no comments. If there aren't any comments I get a "No Cells were Found" error and it stops and highlights the For line.

Any ideas on how to fix it?

Thanks
Gary

johnske
10-15-2007, 06:33 PM
This should be posted as a new question, so I have split the thread.

This is where the ubiquitous On Error Resume Next (on the line before For Each) comes in handy :)

zoom38
10-15-2007, 07:03 PM
Thanks Jonske Problem solved.

lucas
10-15-2007, 08:19 PM
Thread title changed from : Solved:
to : Solved:Error when no comments found

Original poster can edit this to suit using thread tools at the top of the page. I just changed it so it would be easier to find in a search. Also the best way to mark your thread solved is by using the thread tools.