I am using a macro and worksheet, found on the form and changing it to fit my needs, that takes a list of dates and creates a calender. There are multiple events on a single date (or Cell) I want to format the text of individual events to be color coded based on a value. Here is the code I am working with.
But this colors all the text in the cell based on the last event. Not sure where i went wrong. or if someone has a better way of doing this please let me know.
Thanks in advance.
Code:
Private Sub ShowSpecialDates()
Dim I As Integer
Dim TestDate As Date
Dim TestCell As Range
Dim HRange As Range
Dim d As Integer
Dim addtext As String
Dim CellLen As Integer
Dim Newlen As Integer
Set HRange = Range(Range("HDateStart"), Range("HDateStart")(65000).End(xlUp)(1, 1))
For I = 1 To 42
d = Val(Cal(I - 1))
If d > 0 Then
TestDate = DateSerial(CurrYear, CurrMonth, d)
For Each TestCell In HRange
If TestCell.Value = TestDate Then
addtext = TestCell(1, 3).Value
Newlen = Len(TestCell(1, 3))
CellLen = Len(Cal(I - 1))
Select Case TestCell(1, 2).Value
Case "H"
If Range("ShowHoliday").Value = True Then
Cal(I - 1) = Cal(I - 1) & Chr(10) & addtext
Range("CalRng")(I).Characters(CellLen, Newlen).Font.ColorIndex = 3
If Range("MultItems").Value = False Then
Exit For
End If
End If
Case "B"
If Range("ShowBirthday").Value = True Then
Cal(I - 1) = Cal(I - 1) & Chr(10) & addtext
Range("CalRng")(I).Characters(CellLen, Newlen).Font.ColorIndex = 4
If Range("MultItems").Value = False Then
Exit For
End If
End If
Case "O"
If Range("ShowHoliday").Value = True Then
Cal(I - 1) = Cal(I - 1) & Chr(10) & addtext
Range("CalRng")(I).Characters(CellLen, Newlen).Font.ColorIndex = 5
If Range("MultItems").Value = False Then
Exit For
End If
End If
Case Else
End Select
End If
Next TestCell
End If
Next I
End Sub
But this colors all the text in the cell based on the last event. Not sure where i went wrong. or if someone has a better way of doing this please let me know.
Thanks in advance.
Last edited by a moderator: