VBA Conditional formatting on cells with comments

jsflbot

New Member
Joined
Sep 12, 2014
Messages
26
Hello!

I'm trying to figure out how to conditional format cells with particular text in the comment section. If the comments say "Ad" then I would like the box to turn red and if the comments say "TPR" then I want it to turn blue, and if the comments say "Both", then it would turn green.

I used this VBA Code, but it's turning every cell blue if it has a comment....help please:confused:
Sub HighlightCommentCells()
On Error Resume Next
ActiveSheet.UsedRange.SpecialCells(xlCellTypeComments).Interior.Color = vbBlue
On Error GoTo 0
End Sub
 
You can incorporate the UCASE function, which converts all text to Upper case in your VBA code, to handle that.
Code:
Sub MyCommentMacro()

    Dim cell As Range
    
    Application.ScreenUpdating = False
    
    For Each cell In Range("AC5:AN1000")
        If Not cell.Comment Is Nothing Then
            Select Case UCase(cell.Comment.Text)
                Case "AD"
                    cell.Interior.Color = vbRed
                Case "TPR"
                    cell.Interior.Color = vbBlue
                Case "BOTH"
                    cell.Interior.Color = vbGreen
            End Select
        End If
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
Test it out and see (that is the best way of finding our if it works or not).
 
Upvote 0

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