Formato condicional con vba excel

Tengo el siguiente código, lo que quiero es que si en la fila tiene datos aplica el formato y si no que no haga nada.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim valor As String
Dim mesano As String
If Intersect(Target, Range("I:I")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
    valor = Target.Value
    mesano = Sheets("INDICE").Range("J4") & Chr(32) & Sheets("INDICE").Range("L4")
        If IsNumeric(valor) Then
            Range(Cells(Target.Row, "B"), Cells(Target.Row, "L")).Interior.Color = RGB(153, 255, 153)
            Range("A" & Target.Row).ClearContents
            Range("K" & Target.Row).Value = mesano
        ElseIf valor = "PEDIDO" Then
            Range(Cells(Target.Row, "B"), Cells(Target.Row, "L")).Interior.Color = RGB(184, 204, 228)
        Else
            Range(Cells(Target.Row, "B"), Cells(Target.Row, "L")).Interior.ColorIndex = xlNone
            Range("K" & Target.Row).ClearContents
        End If
Application.EnableEvents = True
End Sub

1 Respuesta

Respuesta
1

Te anexo la macro actualizada

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    Dim valor As String
    Dim mesano As String
    If Intersect(Target, Range("I:I")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    valor = Target.Value
    mesano = Sheets("INDICE").Range("J4") & Chr(32) & Sheets("INDICE").Range("L4")
    c1 = WorksheetFunction.Count(Range(Cells(Target.Row, "B"), Cells(Target.Row, "H")))
    c2 = WorksheetFunction.CountA(Range(Cells(Target.Row, "B"), Cells(Target.Row, "H")))
    c3 = WorksheetFunction.Count(Range(Cells(Target.Row, "J"), Cells(Target.Row, "L")))
    c4 = WorksheetFunction.CountA(Range(Cells(Target.Row, "J"), Cells(Target.Row, "L")))
    '
    If c1 > 0 Or c2 > 0 Or c3 > 0 Or c4 > 0 Then
        If IsNumeric(valor) Then
            Range(Cells(Target.Row, "B"), Cells(Target.Row, "L")).Interior.Color = RGB(153, 255, 153)
            Range("A" & Target.Row).ClearContents
            Range("K" & Target.Row).Value = mesano
        ElseIf valor = "PEDIDO" Then
            Range(Cells(Target.Row, "B"), Cells(Target.Row, "L")).Interior.Color = RGB(184, 204, 228)
        Else
            Range(Cells(Target.Row, "B"), Cells(Target.Row, "L")).Interior.ColorIndex = xlNone
            Range("K" & Target.Row).ClearContents
        End If
    End If
    Application.EnableEvents = True
End Sub
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas