PC Review


Reply
Thread Tools Rate Thread

Center Comment Over Selected Cell

 
 
inthepickle
Guest
Posts: n/a
 
      26th Dec 2006
I found this useful bit of code on
http://www.contextures.com/xlcomments03.html
With this code, comments are displayed in the center of the active
window's visible range. I have tried to modify this code to center the
comments over the selected cell. I am not very good with VB in Excel,
and I have not been able to make the necessary modification. Can
someone please give me the code that would allow me to do what I want.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim rng As Range
Dim cTop As Long
Dim cWidth As Long
Dim cmt As Comment
Dim sh As Shape

Application.DisplayCommentIndicator = xlCommentIndicatorOnly

Set rng = ActiveWindow.VisibleRange
cTop = rng.Top + rng.Height / 2
cWidth = rng.Left + rng.Width / 2

If ActiveCell.Comment Is Nothing Then
'do nothing
Else
Set cmt = ActiveCell.Comment
Set sh = cmt.Shape
sh.Top = cTop - sh.Height / 2
sh.Left = cWidth - sh.Width / 2
cmt.Visible = True
End If

End Sub

 
Reply With Quote
 
 
 
 
Debra Dalgleish
Guest
Posts: n/a
 
      27th Dec 2006
If you change the range reference to the active cell, it should centre
the comment over that cell:

Set rng = ActiveCell


inthepickle wrote:
> I found this useful bit of code on
> http://www.contextures.com/xlcomments03.html
> With this code, comments are displayed in the center of the active
> window's visible range. I have tried to modify this code to center the
> comments over the selected cell. I am not very good with VB in Excel,
> and I have not been able to make the necessary modification. Can
> someone please give me the code that would allow me to do what I want.
>
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>
> Dim rng As Range
> Dim cTop As Long
> Dim cWidth As Long
> Dim cmt As Comment
> Dim sh As Shape
>
> Application.DisplayCommentIndicator = xlCommentIndicatorOnly
>
> Set rng = ActiveWindow.VisibleRange
> cTop = rng.Top + rng.Height / 2
> cWidth = rng.Left + rng.Width / 2
>
> If ActiveCell.Comment Is Nothing Then
> 'do nothing
> Else
> Set cmt = ActiveCell.Comment
> Set sh = cmt.Shape
> sh.Top = cTop - sh.Height / 2
> sh.Left = cWidth - sh.Width / 2
> cmt.Visible = True
> End If
>
> End Sub
>



--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html

 
Reply With Quote
 
inthepickle
Guest
Posts: n/a
 
      27th Dec 2006
Thanks Debra. I knew it would be something really simple.

 
Reply With Quote
 
Debra Dalgleish
Guest
Posts: n/a
 
      27th Dec 2006
You're welcome!

inthepickle wrote:
> Thanks Debra. I knew it would be something really simple.
>



--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html

 
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
Read in cell value and comment from 2 selected cells Chuck Microsoft Excel Programming 3 18th Jun 2009 03:29 PM
a comment box that only displays when the cell is actually selected Paul Ponzelli Microsoft Excel Discussion 5 6th Mar 2007 11:17 PM
a comment box that only displays when the cell is actually selected Paul Ponzelli Microsoft Excel Programming 5 6th Mar 2007 11:17 PM
displaying a comment only when the cell is selected Jeff Microsoft Excel Misc 2 6th Jul 2005 09:21 AM
displaying a comment only when the cell is selected Jeff Microsoft Excel Misc 1 6th Jul 2005 08:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:11 PM.