Get address of cell with conditional formatting in VBA

qnguyen

New Member
Joined
Aug 7, 2019
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have in column A various strings, and a rule that highlights certain ones in red.

Is there an easy way to get the reference of the first cell that has been highlighted? For example, if the cell on row 53 is highlighted, I want to get "A53"

I tried FormatConditions.Count but that only tells me how many cells there are in the column. I can also loop through each cell with the formatting rule, but that kind of defeats the purpose.

Thanks!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Are you using a formula within your conditional formatting set up window? If so, what is the formulatext?
 
Upvote 0
Assuming the interior highlight color is red, you could use the DisplayFormat Property... Something along these lines:

Code:
If Range("A53").DisplayFormat.Interior.Color = vbRed Then

    MsgBox "A53 highlighted"


End If
 
Upvote 0
Perhaps something like
Code:
Dim oneCondition As FormatCondition
Dim oneCell As Range

For Each oneCondition In Range("A:A").FormatConditions
    For Each oneCell In oneCondition.AppliesTo.Cells
        With oneCell
            If .Interior.Color <> .DisplayFormat.Interior.Color Then
                MsgBox oneCell.Address " CF active"
            End If
        End With
    Next oneCell
Next oneCondition
 
Upvote 0
Thank you. I ended up modifying mikererickson's solution, though his works fine. Just need to change
Code:
MsgBox oneCell.Address [COLOR=#ff0000]&[/COLOR] " CF active"

I used
Code:
Dim cellcfexist as Range

If Range("A:A").FormatConditions.Count > 0 Then
        For Each cellcfexist In Range("A:A")
            If cellcfexist.DisplayFormat.Interior.Color <> 16777215 Then 'this color is excel's standard white'
                MsgBox cellcfexist.Row
            End If
        Next cellcfexist
    End If
 
Upvote 0

Forum statistics

Threads
1,223,704
Messages
6,173,984
Members
452,540
Latest member
haasro02

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