Adding a Comment to Filtered Range

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
608
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to add a comment to a filtered range in column B and I get an object doesn’t support error.

This is the filter and works correctly

VBA Code:
Worksheets("feb").Range("A2").AutoFilter Field:=2, Criteria1:=Array("3216", "3227", "3256", "3290"), Operator:=xlFilterValues

I tired using this to add the comment

VBA Code:
Worksheets("Feb").AutoFilter.Range.Columns(2).Offset(1, 0).Resize(Rng.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible).AddComment "HI"

This worked for the first visible cell so thought I was close but stuck

VBA Code:
With Worksheets("Feb").Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row).SpecialCells(xlCellTypeVisible)
       .Cells.NoteText "Hi"
End With



Any help appreciated
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You will need to loop through the cells.
Try
VBA Code:
   Dim Cl As Range, Rng As Range
   
   Set Rng = Worksheets("Feb").AutoFilter.Range.Columns(2).Offset(1, 0).Resize(Rng.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible)
   For Each Cl In Rng
      Cl.NoteText "Hi"
   Next Cl
 
Upvote 0
Solution
You will need to loop through the cells.
Try
VBA Code:
   Dim Cl As Range, Rng As Range
  
   Set Rng = Worksheets("Feb").AutoFilter.Range.Columns(2).Offset(1, 0).Resize(Rng.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible)
   For Each Cl In Rng
      Cl.NoteText "Hi"
   Next Cl
Works perfectly! I was moving towards a loop but thought there might be something else with a range type function. Thank you very much
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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