Conditional Formatting - only recognizing empty cells

Bags

Board Regular
Joined
May 28, 2003
Messages
64
Hi all - I am having trouble with the following macros. What I am trying to get it to do is loop through all of the cells in my used range, and if there is a cell that is shaded red, then put true in the last column. It works when the cell is empty and shaded red, but if a cell has a value and is shaded red, it doesn't recognize it. Any help with this is greatly appreciated.

Also, I only need one red cell for the condition to be true - is there a way that once the condition is satisfied to force a move to the next row - or should I be checking rows instead of cells to make it faster?

Thanks again for any help.
Cheers.


Sub ColorCells()
Dim myRange As Range
Dim i As Long, j As Long
Dim LastCol As Integer

Range("IV1").End(xlToLeft).Select
LastCol = ActiveCell.column + 1
Cells(1, LastCol).Select
Selection.FormulaR1C1 = "Validation Error"

Set myRange = ActiveSheet.UsedRange
For i = 1 To myRange.Rows.Count
For j = 1 To myRange.Columns.Count
If myRange.Cells(i, j).Interior.ColorIndex = 3 Then
Cells(i, LastCol).Value = "True"
End If
Next j
Next i
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,203,600
Messages
6,056,203
Members
444,850
Latest member
dancasta7

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