View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default Code to add comments to selected cells within a selected range

So if I select a number of cells in a row, maybe even two rows or a few cells in a few rows, I will have a "selected range". While selected I run the Sub MySelectedRange() and if vbyes from the message box then I select any number of cells in the "selected range" (and accidentally select a cell outside that range) click OK on the InputBox

Now do the stuff I have commented out. AND it would EXCLUDE that accidental selection I made.

I can get the comments where I want them to an extent, but cannot exclude the accidental selection or make the comments go back to Hide, except manually.

I want to preserve the ability to add text to the comments and then when I go to the next cell to add text to it the previous goes to hide.

Unless I am wrong, you cannot add text any of the comments/cells in the middle of the code running, so I am stumped on how to access the cells waiting for a comment.

Maybe will have to take the cells one at a time with some different code...?

Thanks,
Howard

Option Explicit

Sub MySelectedRange()

Dim myCheck

myCheck = MsgBox("Do you want add comments?", vbYesNo)
If myCheck = vbNo Then
Exit Sub
Else
Set rRange = Application.InputBox("With the ctrl key held down, use your mouse" _
& vbCr & "to click on the cells you want to add a Comment.", _
"Comment This Hour", , , , , , 8)

' Put the code below here to act on each of the cells selected for a comment
' and somehow revert the comments back to Hide (for mouse-over viewing) when it goes to next cell.
' The code below as is works great but leaves the comment Visible.

End If
End Sub

Sub CommentAddOrEdit()
'method suggested by Jon Peltier 2006-03-04
'adds new plain text comment or adds text
'at end of existing comment text
Dim cmt As Comment
Set cmt = ActiveCell.Comment
If cmt Is Nothing Then
Set cmt = ActiveCell.AddComment
cmt.Text Text:=""
End If

'type to add comment text to selected shape
cmt.Visible = True
cmt.Shape.Select

End Sub