Consulting

Results 1 to 4 of 4

Thread: Solved:Error when no comments found

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location

    Solved:Error when no comments found

    I have another issue with comments. I have the following code in a Worksheet change event for formatting comments.
    [vba]

    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
    [/vba]

    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

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location
    Thanks Jonske Problem solved.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •