PC Review


Reply
Thread Tools Rate Thread

Clearing Comments

 
 
kirkm
Guest
Posts: n/a
 
      22nd Feb 2009

I'm using this code in a function and sending in the
line number as 'p' -

--
With Range("O" & Val(p))
If Not .Comment Is Nothing Then
With .Comment
.Visible = False
End With
End If
End With
--

It is feasible to use the highest line number insted of p
avoiding the need to calcualte p - or might that be
significantly slower?

Perhaps there's a better method to globally hide
any/all comments ?


Thanks - Kirk
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Feb 2009
To clear contents and comments:
Sub dk()
ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeComments).Delete
End Sub

To clear comments only:

Sub sl()
Dim c As Comment
For Each c In ActiveSheet.Comments
If Not c Is Nothing Then
c.Delete
End If
Next
End Sub





"kirkm" wrote:

>
> I'm using this code in a function and sending in the
> line number as 'p' -
>
> --
> With Range("O" & Val(p))
> If Not .Comment Is Nothing Then
> With .Comment
> .Visible = False
> End With
> End If
> End With
> --
>
> It is feasible to use the highest line number insted of p
> avoiding the need to calcualte p - or might that be
> significantly slower?
>
> Perhaps there's a better method to globally hide
> any/all comments ?
>
>
> Thanks - Kirk
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd Feb 2009
The help files for the Comments Collection Object (found by pressing F1 on
the word "Comments") offers this code example...

Use the Comments property to return the Comments collection. The following
example hides all the comments on worksheet one.

Set cmt = Worksheets(1).Comments
For Each c In cmt
c.Visible = False
Next

--
Rick (MVP - Excel)


"kirkm" wrote in message news:(E-Mail Removed)...
>
> I'm using this code in a function and sending in the
> line number as 'p' -
>
> --
> With Range("O" & Val(p))
> If Not .Comment Is Nothing Then
> With .Comment
> .Visible = False
> End With
> End If
> End With
> --
>
> It is feasible to use the highest line number insted of p
> avoiding the need to calcualte p - or might that be
> significantly slower?
>
> Perhaps there's a better method to globally hide
> any/all comments ?
>
>
> Thanks - Kirk


 
Reply With Quote
 
kirkm
Guest
Posts: n/a
 
      22nd Feb 2009
On Sat, 21 Feb 2009 19:18:01 -0800, JLGWhiz
<(E-Mail Removed)> wrote:

>To clear contents and comments:
>Sub dk()
> ActiveSheet.UsedRange. _
> SpecialCells(xlCellTypeComments).Delete
>End Sub
>
>To clear comments only:
>
>Sub sl()
> Dim c As Comment
> For Each c In ActiveSheet.Comments
> If Not c Is Nothing Then
> c.Delete
> End If
> Next
>End Sub


I found that both routines c.Delete removes the comment
completely.

Cheers - Kirk
 
Reply With Quote
 
kirkm
Guest
Posts: n/a
 
      22nd Feb 2009
On Sat, 21 Feb 2009 22:18:56 -0500, "Rick Rothstein"
<(E-Mail Removed)> wrote:

> The following
>example hides all the comments on worksheet one.
>
>Set cmt = Worksheets(1).Comments
>For Each c In cmt
> c.Visible = False
>Next


Yes, would there be any speed increase
tospecify a column rather thann the whole sheet?

Assuming it's possible ?

Thanks - Kirk


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Feb 2009
Yes, both will remove all comments, but the first one also removes any other
values in the cell and then shifts cells upward in those columns. So, if you
only want to remove comments, the second one is probably what you should use.
You can specify any range of cells. Example:

For Each c In ActiveSheet.Range("A2:G40").Comments
'code to delete
Next

"kirkm" wrote:

> On Sat, 21 Feb 2009 19:18:01 -0800, JLGWhiz
> <(E-Mail Removed)> wrote:
>
> >To clear contents and comments:
> >Sub dk()
> > ActiveSheet.UsedRange. _
> > SpecialCells(xlCellTypeComments).Delete
> >End Sub
> >
> >To clear comments only:
> >
> >Sub sl()
> > Dim c As Comment
> > For Each c In ActiveSheet.Comments
> > If Not c Is Nothing Then
> > c.Delete
> > End If
> > Next
> >End Sub

>
> I found that both routines c.Delete removes the comment
> completely.
>
> Cheers - Kirk
>

 
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
Merge Comments / Wrap comments / Concatonate Comments Gary Microsoft Access Queries 4 15th Apr 2009 03:46 PM
Excel 2007 - Clearing All Comments Jeff Lowenstein Microsoft Excel Misc 1 11th Apr 2009 01:01 AM
Clearing Comments? (PeteCresswell) Microsoft Excel Programming 6 22nd Jan 2007 10:07 AM
Code seems to crash after clearing comments L. Howard Kittle Microsoft Excel Programming 2 20th Feb 2006 06:43 PM
Code crashes after clearing comments L. Howard Kittle Microsoft Excel Worksheet Functions 2 20th Feb 2006 04:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 PM.