Inspired by this question, I went down a rabbit hole trying to discover the maximum allowable number of conditional formatting rules that can be applied to a cell. I have never heard of such a limit. In my research I did find references to Excel 2007 and earlier (here and here), but no references to later versions of Excel. It seems in earlier versions, the maximum number of conditional formatting rules was 3.
So, in order to find out if there was a maximum in Excel 2016, I wrote a macro to create thousands of conditional formatting rules:
Sub CondForm()
On Error GoTo ErrHandle
Application.ScreenUpdating = False
Dim Upper As Integer
Upper = 8000
Dim Start As Double
Start = Timer
Dim Rng As Range
Set Rng = Range("A1")
Dim Text() As String
ReDim Text(1 To Upper)
Rng.FormatConditions.Delete
For i = 1 To Upper
Text(i) = "Text" & i
With Rng.FormatConditions.Add(xlCellValue, Operator:=xlEqual, Formula1:=Text(i))
.Interior.Color = RGB(Int(255 * Rnd), Int(255 * Rnd), Int(255 * Rnd))
End With
Next i
ExitHandle:
Application.ScreenUpdating = True
Debug.Print Upper & ", " & Timer - Start
Exit Sub
ErrHandle:
MsgBox "There was an Error: " & Chr(10) & Err.Number & ", " & Err.Description, vbExclamation
Resume ExitHandle
End Sub
I was able to write at least 10,000 individual rules for one cell. However, anything more than 5,000 caused my file to crash when editing a cell. It should be noted that the time it took to run the macro appeared to increase exponentially. It took approximately 6 seconds to write 1,000 rules, 3 minutes to write 5,000 rules, and about 23 minutes to write 10,000 rules.
Rather than continue to spot check large numbers randomly (and wait several hours for the results), I thought I'd go to the community with this one. This a primarily academic pursuit (I highly doubt I'll ever need more than 5,000 conditional formatting rules), so please let me know if this question is not appropriate for the forum.
My question is: Is there a maximum number of conditional formatting rules that can be applied in Excel?
If no one knows of a maximum, is there a programmatic way to determine the maximum? Preferably one that won't take 5 hours to run...
Thanks for the consideration!