Macro para Cambia Fuente de Color
Necesito me ayuden a moficar una macro que he elaborado para que al restar dos fechas de acuerdo al numero de días que genere como resultado me cambie el color de la fuente, la macro que tengo es la siguiente:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim valor As Date
Dim valor1 As Date
Dim col As Integer
col = 23
If ActiveCell.Column = col And ActiveCell.Row > 2 Then
valor = ActiveCell.Offset(-1, 0).Value
valor1 = ActiveCell.Offset(-1, -21).Value
If valor > 0 Then
fila = ActiveCell.Offset(-1, 0).Row
Cells(fila, col).Select
dias = valor - valor1
Select Case dias
Case 1:
Selection.Font.ColorIndex = 3
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Case 2:
Selection.Interior.ColorIndex = xlNone
Selection.Font.ColorIndex = 3
Case 3:
Selection.Font.ColorIndex = 5
Case Else:
Selection.Interior.ColorIndex = xlNone
Selection.Font.ColorIndex = 0
End Select
Cells(fila + 1, col).Select
End If
End If
End Sub
Esta macro me funciona muy bien pero tengo que activar la celda manualmente para que me funcione y yo necesito que sin activar la celda manualmente realice los cambios indicados.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim valor As Date
Dim valor1 As Date
Dim col As Integer
col = 23
If ActiveCell.Column = col And ActiveCell.Row > 2 Then
valor = ActiveCell.Offset(-1, 0).Value
valor1 = ActiveCell.Offset(-1, -21).Value
If valor > 0 Then
fila = ActiveCell.Offset(-1, 0).Row
Cells(fila, col).Select
dias = valor - valor1
Select Case dias
Case 1:
Selection.Font.ColorIndex = 3
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Case 2:
Selection.Interior.ColorIndex = xlNone
Selection.Font.ColorIndex = 3
Case 3:
Selection.Font.ColorIndex = 5
Case Else:
Selection.Interior.ColorIndex = xlNone
Selection.Font.ColorIndex = 0
End Select
Cells(fila + 1, col).Select
End If
End If
End Sub
Esta macro me funciona muy bien pero tengo que activar la celda manualmente para que me funcione y yo necesito que sin activar la celda manualmente realice los cambios indicados.
1 Respuesta
Respuesta de Elsa Matilde
1