Excel VBA: Application.DisplayCommentIndicator

leonlai

Board Regular
Joined
Mar 22, 2019
Messages
77
Hi,

I understand (from surfing the net) that we can hide and show comments in Excel by using:

Application.DisplayCommentIndicator=xlCommentIndicatorOnly (to hide comments)
or
Application.DisplayCommentIndicator=xlCommentAndIndicator (to show comments)


However, this will hide or show ALL comments in the whole workbook.

Is it possible to apply these commands to a selected range only, i.e. to hide or show comments only in the small range selected by the user (using Application.Selection)?

How can this be done?

Thanks
Leon
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Not sure this is exactly like you want it but...
Paste below into a Standard Module. Then Highlight the Range you want to hide all currently showing Comments and Run the Macro.
All Comments in the Range will be hidden. Afterwards, whenever you want to REINSTATE All Shown Comments Just Click (On the Review Tab)
"SHOW ALL COMMENTS".

Code:
Sub HideCommentsInSelectedRange()
Set Rng = Selection
    With Rng
        .Cells.SpecialCells(xlCellTypeComments).Select
        sAddress = .Cells.SpecialCells(xlCellTypeComments).Address
        Arr = Split(sAddress, ",")
        Icnt = UBound(Arr)
            For i = 0 To Icnt
            Range(Range(Arr(i)).Address).Comment.Visible = False
            Next i
    End With
Set Rng = Nothing
End Sub
 
Upvote 0
Hi, Jim

Thanks for your reply.

When I run the macro, the following line shows an error:

Code:
Range(Range(Arr(i)).Address.Comment.Visible = False

I am not very good at debugging. So, maybe you can tell me what's wrong.

Best Regards,
Leon
 
Upvote 0
Line should be:
Range(Range(Arr(i)).Address).Comment.Visible = False

Somehow the ")" fell out following the word address.
Enter it and try again.
 
Upvote 0
Jim,

I tried again after adding the missing bracket. There is a bug on the same line.

The following Error is displayed:

Run-time error 91
Object variable or With block variable not set.


Leon
 
Upvote 0
OK, one LAST TIME.. Change same full codeline to:

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Range(Arr(i)).Comment.Visible = False[/FONT]
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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