Agregar formato de cela y colorear

Pregunta para dante tengo este código que me hiciste anda bárbaro quisiera agregarle lo siguiente

Selection.NumberFormat = "$* #,##0;[Red]$ * -#,##0"    (darle este formato a las celdas donde se pegan los importes o sea las celdas de la columna H,I,J, y K

Interior.Color = 49407 (a la celda de la columna K)

------------------------------------------------------------------------------------------------------------------------

Private Sub Worksheet_Change(ByVal Target As Range)
'Por.Dante Amor
If Not Intersect(Target, Range("B:E")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
If Target.Row < 4 Then Exit Sub
If Cells(Target.Row, "A") = "" Then
MsgBox "No hay fecha"
Exit Sub
End If
f = Month(Cells(Target.Row, "A")) + 3
Cells(f, "G") = Format(Cells(Target.Row, "A"), "mmm") & "-" & Year(Date)
c = Target.Column + 6
Cells(f, c) = Cells(f, c) + Target.Value
Cells(f, "K") = Cells(f, "K") + Target.Value
End If
End Sub

1 Respuesta

Respuesta
1

Te anexo la macro actualizada

Private Sub Worksheet_Change(ByVal Target As Range)
'Por.Dante Amor
    If Not Intersect(Target, Range("B:E")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Row < 4 Then Exit Sub
        If Cells(Target.Row, "A") = "" Then
            MsgBox "No hay fecha"
            Exit Sub
        End If
        f = Month(Cells(Target.Row, "A")) + 3
        Cells(f, "G") = Format(Cells(Target.Row, "A"), "mmm") & "-" & Year(Date)
        c = Target.Column + 6
        Cells(f, c) = Cells(f, c) + Target.Value
        Cells(f, c).NumberFormat = "$* #,##0;[Red]$ * -#,##0"
        Cells(f, "K") = Cells(f, "K") + Target.Value
        Cells(f, "K").Interior.Color = 49407
    End If
End Sub

Prueba y me comentas

Así esta perfecto dante lo único que falta es que en la fecha quiero que quede este formato

Ene-2015

Feb-2015

etc...

Porque ahora me la toma de otra manera

Y te pregunto otro cosa cuando llego al otro año por ejemplo a Ene-2016 me lo suma en la fila 4 sumándolo a Ene-2015 en lugar de Ene-2016 en la fila que sigue a dic-2015 gracias esto lo hace aunque cambie la fecha de la compu el resto esta perfecto es lo único que me faltaría

El formato de fecha es Feb-2015

¿Qué es lo que te aparece?

Te anexo la macro para que te busque por mes y año

Private Sub Worksheet_Change(ByVal Target As Range)
'Por.Dante Amor
    If Not Intersect(Target, Range("B:E")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Row < 4 Then Exit Sub
        If Cells(Target.Row, "A") = "" Then
            MsgBox "No hay fecha"
            Exit Sub
        End If
        '
        mes = Format(Cells(Target.Row, "A"), "mmm")
        año = Year(Cells(Target.Row, "A"))
        fecha = mes & "-" & año
        Set b = Columns("G").Find(fecha, lookat:=xlWhole)
        If Not b Is Nothing Then
            f = b.Row
        Else
            f = Range("G" & Rows.Count).End(xlUp).Row + 1
            If f < 4 Then f = 4
        End If
        Cells(f, "G") = "'" & fecha
        c = Target.Column + 6
        Cells(f, c) = Cells(f, c) + Target.Value
        Cells(f, c).NumberFormat = "$* #,##0;[Red]$ * -#,##0"
        Cells(f, "K") = Cells(f, "K") + Target.Value
        Cells(f, "K").Interior.Color = 49407
    End If
End Sub

Dante esta todo perfecto para terminar necesito agregarle al código que todos los diciembre me lo cierre con un línea com te mando en la imagen muchas gracias amigo y ya te mando la pregunta en todoexpertos por esta línea abrazo

Te anexo la macro actualizada

Private Sub Worksheet_Change(ByVal Target As Range)
'Por.Dante Amor
    If Not Intersect(Target, Range("B:E")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Row < 4 Then Exit Sub
        If Cells(Target.Row, "A") = "" Then
            MsgBox "No hay fecha"
            Exit Sub
        End If
        '
        mes = Format(Cells(Target.Row, "A"), "mmm")
        año = Year(Cells(Target.Row, "A"))
        fecha = mes & "-" & año
        Set b = Columns("G").Find(fecha, lookat:=xlWhole)
        If Not b Is Nothing Then
            f = b.Row
        Else
            f = Range("G" & Rows.Count).End(xlUp).Row + 1
            If f < 4 Then f = 4
        End If
        Cells(f, "G") = "'" & fecha
        c = Target.Column + 6
        Cells(f, c) = Cells(f, c) + Target.Value
        Cells(f, c).NumberFormat = "$* #,##0;[Red]$ * -#,##0"
        Cells(f, "K") = Cells(f, "K") + Target.Value
        Cells(f, "K").Interior.Color = 49407
        With Range(Cells(f, "G"), Cells(f, "K")).Borders(xlEdgeBottom)
            If mes = "Dic" Then
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            Else
                .LineStyle = xlNone
            End If
        End With
    End If
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas