Code to add comments to selected cells within a selected range
Hi Howard,
Am Tue, 28 Jan 2014 00:02:16 -0800 (PST) schrieb L. Howard:
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.
don't select a range before the InputBox. First run the macro and then
select a range with the InputBox:
Sub MySelectedRange()
Dim myCheck As Integer, myCell As Integer
Dim rngC As Range, rRange As Range
Dim myCom As String
myCheck = MsgBox("Do you want add comments?", vbYesNo)
If myCheck = vbYes Then _
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", Type:=8)
For Each rngC In rRange
If rngC.Comment Is Nothing Then
myCell = MsgBox("Do you want to add a comment to " _
& rngC.Address(0, 0), vbYesNo)
If myCell = vbYes Then
myCom = Application.InputBox("Enter your comment text", _
"My comment", Type:=2)
Else
myCom = vbNullString
End If
If myCom = vbNullString Then GoTo SKIP
rngC.AddComment myCom
End If
SKIP:
Next
End Sub
Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
|