kevvukeka
07-28-2014, 11:06 PM
Hi All.
I have to insert conditional formatting in an excel and I chose to do it through VBA. In the attached excel sheet in COl N there is a formula that would calculate the no of days between two given dates. I have to assign different color when no of days in column N exceeds a limit. I would add fresh data everyday after the last row in the given data. I tried using the below code but I get "Type mismatch error". Can someone plz check and help me what is missing here.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
If Not Intersect(Target, Range("N:N")) Is Nothing Then
Select Case Target
Case 31 To 60
Target.Interior.ColorIndex = 10213316
Case 61 To 90
Target.Interior.ColorIndex = 14857357
Case 91 To 110
Target.Interior.ColorIndex = 9420794
Case 111 To 1000
Target.Interior.ColorIndex = 5197823
Case 0 To 30
Target.Interior.ColorIndex = xlNone
End Select
End If
End Sub
I have to insert conditional formatting in an excel and I chose to do it through VBA. In the attached excel sheet in COl N there is a formula that would calculate the no of days between two given dates. I have to assign different color when no of days in column N exceeds a limit. I would add fresh data everyday after the last row in the given data. I tried using the below code but I get "Type mismatch error". Can someone plz check and help me what is missing here.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
If Not Intersect(Target, Range("N:N")) Is Nothing Then
Select Case Target
Case 31 To 60
Target.Interior.ColorIndex = 10213316
Case 61 To 90
Target.Interior.ColorIndex = 14857357
Case 91 To 110
Target.Interior.ColorIndex = 9420794
Case 111 To 1000
Target.Interior.ColorIndex = 5197823
Case 0 To 30
Target.Interior.ColorIndex = xlNone
End Select
End If
End Sub