S
SteelAdept
I am having severe issues getting Excel to automatically set the color
attribute for a cell based on values in the cell. I have tried numerous
times with numerous methods including using the macro recorder to create the
code. However, once I create the code and build my function around it, it
doesn't work! The entire function is below:
Function DecideColor(cTrain As Date, cDoc As Date)
Dim test As String
'This compares the two dates
If cDoc < cTrain Then
ActiveCell.Select
Selection.Interior.ColorIndex = 35
test = "Good"
ElseIf cDoc > cTrain Then
ActiveCell.Select
Selection.Interior.ColorIndex = 3
test = "Bad"
End If
DecideColor = test
End Function
Note, for testing purposes, I am simply puting in dates to ensure they are
different. There are many border situations I will deal with later (such as
what if the two dates are the same, et. al.). When I run this function, it
compares the dates properly, and enters the "Good" or "Bad" appropriately, so
it isn't an issue with the compare statements. It is ONLY that the color
NEVER changes! This is absolutely frustrating. Is there anyone who can help?
attribute for a cell based on values in the cell. I have tried numerous
times with numerous methods including using the macro recorder to create the
code. However, once I create the code and build my function around it, it
doesn't work! The entire function is below:
Function DecideColor(cTrain As Date, cDoc As Date)
Dim test As String
'This compares the two dates
If cDoc < cTrain Then
ActiveCell.Select
Selection.Interior.ColorIndex = 35
test = "Good"
ElseIf cDoc > cTrain Then
ActiveCell.Select
Selection.Interior.ColorIndex = 3
test = "Bad"
End If
DecideColor = test
End Function
Note, for testing purposes, I am simply puting in dates to ensure they are
different. There are many border situations I will deal with later (such as
what if the two dates are the same, et. al.). When I run this function, it
compares the dates properly, and enters the "Good" or "Bad" appropriately, so
it isn't an issue with the compare statements. It is ONLY that the color
NEVER changes! This is absolutely frustrating. Is there anyone who can help?