Instead of formatting each column separately, you can apply one formula to conditional formatting.
The formula in conditional formatting must be given in the local language. The following code also solves this problem.
Sub Formatting_2()
Dim rng As Range
Set rng = Range("B4:AI10000")
rng.FormatConditions.Delete
rng.FormatConditions.Add Type:=xlExpression, Formula1:= _
GetLocalFormula("=IF(AND(LEN(B$1)>0,LEN(B4)>0),OR(B4<B$1,B4>B$2))")
'Polish version "=JEŻELI(ORAZ(DŁ(B$1)>0;DŁ(B4)>0);LUB(B4<B$1;B4>B$2))"
rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
With rng.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14013951
.TintAndShade = 0
End With
rng.FormatConditions(1).StopIfTrue = False
End Sub
Function GetLocalFormula(strUSFormula As String) As String
Dim rngBlanks As Range
Dim rng As Range
Dim calcMode As XlCalculation
Dim eventMode As Boolean
Dim screenMode As Boolean
With ActiveSheet.UsedRange
On Error Resume Next
Set rngBlanks = .SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not rngBlanks Is Nothing Then
For Each rng In rngBlanks.Cells
If rng.NumberFormat <> "@" Then
Exit For
End If
Next rng
If rng Is Nothing Then
Set rng = .Offset(, .Columns.Count + 1)(1)
End If
With Application
screenMode = .ScreenUpdating
eventMode = .EnableEvents
calcMode = .Calculation
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
rng.Formula = strUSFormula
GetLocalFormula = rng.FormulaLocal
rng.ClearContents
With Application
.Calculation = calcMode
.EnableEvents = eventMode
.ScreenUpdating = screenMode
End With
Else
MsgBox "The active sheet is probably protected!" & vbLf & _
"I can't define a formula", vbCritical
End If
End With
End Function
Artik