Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Center Comment Over Selected Cell

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Center Comment Over Selected Cell

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Center Comment Over Selected Cell

Thanks Debra. I knew it would be something really simple.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Center Comment Over Selected Cell

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Center Comments on Center of Screen Raymond W. Excel Discussion (Misc queries) 5 September 15th 09 04:58 PM
Merge and Center and Center Accross Selection Bojingles03 New Users to Excel 3 March 17th 09 07:05 PM
displaying a comment only when the cell is selected Jeff Excel Discussion (Misc queries) 2 July 6th 05 09:21 AM
displaying a comment only when the cell is selected Jeff Excel Discussion (Misc queries) 1 July 6th 05 08:18 AM
Center Across Selection Vertically Help. I am trying to center te. msond Excel Discussion (Misc queries) 1 March 29th 05 12:37 PM


All times are GMT +1. The time now is 03:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"