how to expand "selection" to a range instead of "active cell" to show comment/note...

sadams1

Board Regular
Joined
Aug 19, 2006
Messages
228
hello & I hang my head in shame that I can't figure this out. Have the follow code...
*********************************************

Sub cmtShow()

With Selection

.Comment.Visible = True
.Comment.Shape.Select True

End With
Application.CutCopyMode = False


End Sub

************************************************

This works great for the "active cell" but if a range is selected, an error about "block variable not set" comes up. What am I missing using "selection" as it should work for ranges (?) Any insight would be greatly appreciated! Thank you for your time!
Steve
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
What if you change "With Selection" to "For Each c In Selection"?
 
Upvote 0
hello & thank you for the reply! I'm a hack at best so I mess around with stuff until I have ask for help so when I replace "with selection" with "for each c in selection" Visual Basic gets all upset & snarls "COMPILE ERROR! INVALID REFERENCE!" so looks like there's addition syntax? Sorry for sounding stupid but my programming skills are suspect on a good day!
 
Upvote 0
Sorry about that.
What are you trying to accomplish? Just make the Comment visible?
Maybe try so
Code:
Sub Make_Visible()
Dim c As Range
For Each c In Selection
c.Comment.Visible = True
Next c
End Sub
Select the Range in question and run the macro. See if that is what you want.
Next time when asking a question, explain what you want to achieve. Quite often code that does not work is of little or no use.
What is this meant to show you?
Code:
.Comment.Shape.Select True
 
Upvote 0
Sorry for being unclear about the end result...it's hooked up to a "hotkey" so when a cell, or range, is active, the keyboard shortcut makes the comment visible.

Something I noticed is that the code works with contiguous cells but if a cell is blank anywhere in the range, the "block variable not set" error occurs. The ranges will have blank cells so would it possible to tweak the code to handle empty cells? Thank you very much again for your time & insights!
 
Upvote 0
for comparison, this is a macro that resets the comments to a specific spot & usually an entire row or entire column can be selected...

Sub cmtResetRange()
Dim r As Range
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+Shift+Y
'


For Each r In Selection
If Not r.Comment Is Nothing Then
With r.Comment

r.Comment.Shape.Top = r.Comment.Parent.Top + 15
r.Comment.Shape.Left = r.Comment.Parent.Offset(0, 1).Left + 5





End With
End If
Next r
End Sub
 
Upvote 0
Maybe take notice of attached. Makes life so much easier.
 

Attachments

  • Use Code Tags MrExcel.JPG
    Use Code Tags MrExcel.JPG
    50.2 KB · Views: 7
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top