Function correctRedDays()
Dim i As Integer
Dim d As Date
Dim startDate As Date, endDate As Date
Dim dateColumn As Integer
Dim noOfChanges As Integer
Dim normalDayColor As Long, redDayColor As Long, newColor As Long
Dim lastDayYear As Integer
Dim rda() As Date
For i = 3 To 30
If shtDay.Cells(4, i) = "datum" Then
dateColumn = i
Exit For
End If
Next
i = 5
Do While shtDay.Cells(i, dateColumn) <> ""
i = i + 1
Loop
startDate = CDate(shtDay.Cells(5, dateColumn))
endDate = CDate(shtDay.Cells(i - 1, dateColumn))
normalDayColor = shtSetup.Cells(8, 9).Interior.color
redDayColor = shtSetup.Cells(9, 9).Interior.color
For d = startDate To endDate
If Format(d, "yyyy") <> lastDayYear Then
lastDayYear = Format(d, "yyyy")
createRedDayArray lastDayYear, rda()
End If
newColor = IIf(isRedDay(d, rda()), redDayColor, normalDayColor)
If shtDay.Cells(5 + CLng(d - startDate) * 4, 2).Interior.color <> newColor Then
shtDay.Cells(5 + CLng(d - startDate) * 4, 2).Interior.color = newColor
noOfChanges = noOfChanges + 1
End If
Next
MsgBox "Färgen ändrades för " & noOfChanges & " dagar.", vbInformation
End Function