Conditional formatting if there contains user comments

rusa31

New Member
Joined
Jan 31, 2021
Messages
14
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hello,
I need help.
Output : Range of cell change color when cell contains specific Value and comments

the code below not working

VBA Code:
Dim cell As Range
    
    ' Set the range where you want to apply the conditional formatting
    Set rng = Range("A1:A10")  ' Change this range as needed
    
    For Each cell In rng
        If cell.Value = "SpecificValue" And cell.Comment IsNot Nothing Then
            cell.Interior.Color = RGB(255, 0, 0) ' Change color as needed
        End If
    Next cell
End Sub

Thank you.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this code ...

VBA Code:
Public Sub FlagValues()
Dim cell As Range
    
  ' Set the range where you want to apply the conditional formatting
  Set rng = Range("A1:A10")  ' Change this range as needed
  
  For Each cell In rng
    With cell(1, 1)
      If .Value = "SpecificValue" And Not (.Comment Is Nothing) Then
        .Interior.Color = vbRed ' Change color as needed
      Else
        .Interior.Pattern = xlNone
        .Interior.TintAndShade = 0
        .Interior.PatternTintAndShade = 0
      End If
    End With
  Next cell
End Sub

test20230822.xlsm
A
11
22
3SpecificValue
44
55
66
77
8SpecificValue
98
109
Sheet2
 
Upvote 0
Try this code ...

VBA Code:
Public Sub FlagValues()
Dim cell As Range
   
  ' Set the range where you want to apply the conditional formatting
  Set rng = Range("A1:A10")  ' Change this range as needed
 
  For Each cell In rng
    With cell(1, 1)
      If .Value = "SpecificValue" And Not (.Comment Is Nothing) Then
        .Interior.Color = vbRed ' Change color as needed
      Else
        .Interior.Pattern = xlNone
        .Interior.TintAndShade = 0
        .Interior.PatternTintAndShade = 0
      End If
    End With
  Next cell
End Sub

test20230822.xlsm
A
11
22
3SpecificValue
44
55
66
77
8SpecificValue
98
109
Sheet2
The only caveat with that is unlike Conditional Formatting, it is not dynamic. You would have to run it whenever there is a data change.
 
Upvote 0
Per Joe4's comment above. If you want to use a Conditional Formatting formula do the following
- Create a custom formula like the following
VBA Code:
Public Function HasComment(rng As Range)
    HasComment = Not (rng(1, 1).Comment Is Nothing)
End Function

- in the conditional formatting setup - create a new rule for the desired range and enter the following formula for the selected cell
=AND(A1="SpecificValue",HasComment(A1))

Note: A1 was my selected cell and the range was (A1:A10)
 
Upvote 0

Forum statistics

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