VBA For Filtering Comments in a Column

mayoung

Active Member
Joined
Mar 26, 2014
Messages
259
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am using Office 365 excel Is there away to filter Comments NOT Notes in a Column? Can be using a helper column if necessary.
I have the ability to filter Notes in a column but want to filter Comments.
Any help would be appreciated.
 
It might help to know where the comments can be. I tried that code and it hid every row from 2 to 35 yet there are only 3 rows with a comment in any column.
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
It might help to know where the comments can be. I tried that code and it hid every row from 2 to 35 yet there are only 3 rows with a comment in any column.

My Comments are in Column-C starting in row 2. I have data from Columns A through BA
 
Upvote 0
This should raise a message box for every row that contains a comment. If you can test it on a limited range of rows/columns first then it can be tweaked. Change your sheet name from sheet8 to whatever you need. If the msgbox works, I should be able to switch to hiding the rows, but the code might need to be "dumbed" down (because I was in the process before you answered) so it's not currently limited to any particular column when looking for comments
VBA Code:
Sub TestComments()
Dim Lcol As Long, Lrow As Long, i As Long
Dim ws As Worksheet, rng As Range, rnge As Range

Set ws = Sheets("Sheet8")
With ws
     Lrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
     Lcol = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
End With

Set rng = Range(Cells(1, 1), Cells(Lrow, Lcol))
For Each rnge In rng.Cells
     If Not rnge.Comment Is Nothing Then
          MsgBox rnge.Row
     End If
Next

End Sub
.

I also don't seem to be using "i" any more so there's some cleanup to do as well.
 
Upvote 0
This should raise a message box for every row that contains a comment. If you can test it on a limited range of rows/columns first then it can be tweaked. Change your sheet name from sheet8 to whatever you need. If the msgbox works, I should be able to switch to hiding the rows, but the code might need to be "dumbed" down (because I was in the process before you answered) so it's not currently limited to any particular column when looking for comments
VBA Code:
Sub TestComments()
Dim Lcol As Long, Lrow As Long, i As Long
Dim ws As Worksheet, rng As Range, rnge As Range

Set ws = Sheets("Sheet8")
With ws
     Lrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
     Lcol = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
End With

Set rng = Range(Cells(1, 1), Cells(Lrow, Lcol))
For Each rnge In rng.Cells
     If Not rnge.Comment Is Nothing Then
          MsgBox rnge.Row
     End If
Next

End Sub
.

I also don't seem to be using "i" any more so there's some cleanup to do as well.
I will try it and let you know..
 
Upvote 0
Another option you can try, where C is the only column you're worried about looking for comments. Again, you will need to modify sheet name. If you want the code to work on any sheet, then it needs further mods and to be placed in a standard module.
VBA Code:
Sub TestComments2()
Dim Lrow As Long, i As Long

Lrow = Sheets("Sheet8").Cells(Rows.count, "C").End(xlUp).Row
For i = 2 To Lrow
   If Not Range("C" & i).Comment Is Nothing Then
      Rows(i).EntireRow.Hidden = True
   End If
Next

End Sub
 
Upvote 0
I have included a link to my workbook. Both of you codes are in the only module. Please see what you think?

Another option you can try, where C is the only column you're worried about looking for comments. Again, you will need to modify sheet name. If you want the code to work on any sheet, then it needs further mods and to be placed in a standard module.
VBA Code:
Sub TestComments2()
Dim Lrow As Long, i As Long

Lrow = Sheets("Sheet8").Cells(Rows.count, "C").End(xlUp).Row
For i = 2 To Lrow
   If Not Range("C" & i).Comment Is Nothing Then
      Rows(i).EntireRow.Hidden = True
   End If
Next

End Sub
Link To Work Book
 
Upvote 0
Something wrong with your link, I think. Nothing happens.
Why do you want me to look at it anyway? Not working?
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,685
Members
449,463
Latest member
Jojomen56

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