Option Explicit
Sub DoAllRows_2025_22()
Dim r As Long
Application.ScreenUpdating = False
With ActiveSheet
With .Range("DO3:EZ78") 'tova e diapazona v koti trqbva da se iztriqt vsichki condittional
.FormatConditions.Delete
.Interior.ColorIndex = xlColorIndexNone
' clear any empty, but text i.e. 0 length strings
Call .Replace(vbNullString, "###ZZZ###", LookAt:=xlWhole)
Call .Replace("###ZZZ###", vbNullString, LookAt:=xlWhole)
' clear the settings
.Find What:=vbNullString, After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False
.Replace What:=vbNullString, Replacement:=vbNullString, ReplaceFormat:=False
End With
' https://www.rondebruin.nl/win/s9/win012.htm
' Excel 97 = 8
' Excel 2000 = 9
' Excel 2002 = 10
' Excel 2003 = 11
' Excel 2007 = 12
' Excel 2010 = 14
' Excel 2013 = 15
' Excel 2016 = 16
' Excel 2019 and Excel 365 also give you number 16
If Val(Application.Version) > 12 Then 'If Application.Version > 12 Then
For r = 3 To 78 'ot tuk sa redovete ot 3ti red do 78ti red
Call AddCF(r)
Next r
Else
For r = 3 To 79 'ot tuk sa redovete ot 3ti red do 79-Vi red
Call AddInteriorColor(r)
Next r
End If
End With
Application.ScreenUpdating = True
End Sub
Private Sub AddInteriorColor(rowNum As Long)
Dim T1 As Long, T2 As Long, T3 As Long, T4 As Long, T5 As Long, T6 As Long, T7 As Long, T8 As Long, T9 As Long, T10 As Long, T0 As Long
Dim r As Range
Dim c As Long
Set r = ActiveSheet.Rows(rowNum)
With r
If .Cells(1, 157).Value = 0 Then Exit Sub ' no threshholds 15ti red e pyrviqt bonus ili kolonata s godinata 2023(EA) naprimer
T0 = .Cells(1, 117).Value 'DM KOLONA ILI SRAVNENIETO SPRQMO 1.12.2022
T1 = .Cells(1, 157).Value 'tezi 131, 132, 133, 134 ili EA, EB, EC, ED sa bonusite +30,+60,+90,+120 naprimer
T2 = .Cells(1, 158).Value
T3 = .Cells(1, 159).Value
T4 = .Cells(1, 160).Value
T5 = .Cells(1, 161).Value 'new color
T6 = .Cells(1, 162).Value 'new color
T7 = .Cells(1, 163).Value 'new color
T8 = .Cells(1, 164).Value 'new color
T9 = .Cells(1, 165).Value 'new color
T10 = .Cells(1, 166).Value 'new color
Set r = r.Cells(1, 119).Resize(1, 38) 'tuk rcells oznachava ot koq kolona da zapochne da izchislqva ili inache ot 1.1.2023 (DO), a resize 12 oznachava kolko nadqsno koloni
End With
With r
For c = 1 To 38 ' r starts in col C tuk syshto promenqme tow 25 e naprimer ot 1.2023 do 12.2024, t.e 25 reda nadqsno
If .Cells(1, c).Value >= T0 + T10 Then
.Cells(1, c).Interior.Color = rgbSpringGreen 'new color rgbPowderBlue
ElseIf .Cells(1, c).Value >= T0 + T9 Then
.Cells(1, c).Interior.Color = rgbOrchid 'new color
ElseIf .Cells(1, c).Value >= T0 + T8 Then
.Cells(1, c).Interior.Color = rgbOlive 'new color
ElseIf .Cells(1, c).Value >= T0 + T7 Then
.Cells(1, c).Interior.Color = rgbPowderBlue 'new color
ElseIf .Cells(1, c).Value >= T0 + T6 Then
.Cells(1, c).Interior.Color = vbBlue 'new color
ElseIf .Cells(1, c).Value >= T0 + T5 Then
.Cells(1, c).Interior.Color = vbGreen 'new color
ElseIf .Cells(1, c).Value >= T0 + T4 Then
.Cells(1, c).Interior.Color = vbRed
ElseIf .Cells(1, c).Value >= T0 + T3 Then
.Cells(1, c).Interior.Color = vbMagenta
ElseIf .Cells(1, c).Value >= T0 + T2 Then
.Cells(1, c).Interior.Color = vbCyan
ElseIf .Cells(1, c).Value >= T0 + T1 Then
.Cells(1, c).Interior.Color = vbYellow
End If
Next c
End With
End Sub
Private Sub AddCF(rowNum As Long)
Dim T1 As Long, T2 As Long, T3 As Long, T4 As Long, T5 As Long, T6 As Long, T7 As Long, T8 As Long, T9 As Long, T10 As Long
Dim CFormula As String
Dim r As Range
Set r = ActiveSheet.Rows(rowNum)
With r
If .Cells(1, 157).Value = 0 Then Exit Sub ' no threshholds 15ti red e pyrviqt bonus ili kolonata s godinata 2023 naprimer
T1 = .Cells(1, 157).Value 'tezi 131, 132, 133, 134 ili EA, EB, EC, ED sa bonusite +30,+60,+90,+120 naprimer
T2 = .Cells(1, 158).Value
T3 = .Cells(1, 159).Value
T4 = .Cells(1, 160).Value
T5 = .Cells(1, 161).Value 'new color
T6 = .Cells(1, 162).Value 'new color
T7 = .Cells(1, 163).Value 'new color
T8 = .Cells(1, 164).Value 'new color
T9 = .Cells(1, 165).Value 'new color
T10 = .Cells(1, 166).Value 'new color
CFormula = "=$DM" & .Cells(1, 1).Row & "+" 'tuk $DM, se promenq na bukvata(kolonata), koqto ni e za sravnenie, naprimer $DM sprqmo 12 mesec na minalata godina
Set r = r.Cells(1, 119).Resize(1, 38) 'tuk rcells oznachava ot koq kolona da zapochne da izchislqva ili inache ot 1.1.2023, a resize 12 oznachava kolko nadqsno koloni
End With
With r
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T10
.FormatConditions(.FormatConditions.Count).Interior.Color = rgbSpringGreen 'new color
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T9
.FormatConditions(.FormatConditions.Count).Interior.Color = rgbOrchid 'new color
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T8
.FormatConditions(.FormatConditions.Count).Interior.Color = rgbOlive 'new color rgbPowderBlue
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T7
.FormatConditions(.FormatConditions.Count).Interior.Color = rgbPowderBlue 'new color rgbPowderBlue
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T6
.FormatConditions(.FormatConditions.Count).Interior.Color = vbBlue 'new color
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T5
.FormatConditions(.FormatConditions.Count).Interior.Color = vbGreen 'new color
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T4
.FormatConditions(.FormatConditions.Count).Interior.Color = vbRed
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T3
.FormatConditions(.FormatConditions.Count).Interior.Color = vbMagenta
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T2
.FormatConditions(.FormatConditions.Count).Interior.Color = vbCyan
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:=CFormula & T1
.FormatConditions(.FormatConditions.Count).Interior.Color = vbYellow
.FormatConditions(.FormatConditions.Count).StopIfTrue = True
End With
End Sub