Sub formula()
'
' formula Macro
'
'
Application.ScreenUpdating = False
Range("I4").Select
Range("I4").FormulaLocal = "=SI(H4>0,SIFECHA(G4,H4,""d""),SIFECHA(G4,$D$1,""d""))"
Selection.AutoFill Destination:=Range("I4:I96")
Range("I4:I96").Select
Range("I4").Select
Range("K4").Select
Range("K4").FormulaLocal = "=SI(J4>0,SIFECHA(H4,J4,""d""),SI(H4>0,SIFECHA(H4,$D$1,""d""),SIFECHA(G4,$D$1,""d"")))"
Range("K4").Select
Selection.AutoFill Destination:=Range("K4:K96")
Range("K4:K96").Select
Range("I4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("K4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlGeneral
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("K4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("Z4").Select
Range("Z4").FormulaLocal = "=SI(I4<=2,I4,-I4)"
Range("Z4").Select
Selection.AutoFill Destination:=Range("Z4:Z96")
Range("Z4:Z96").Select
Range("Z4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("AA4").Select
Range("AA4").FormulaLocal = "=SI(O4=""NO"",SI(Y(Z4<0,H4=""""),""VENCIDO SIN AUTORIZAR"",SI(Y(Z4<0,H4>0),""AUTORIZADA CON VENCIMIENTO"",SI(H4>0,""AUTORIZADA SIN VENCIMIENTO"",SI(Z4=2,""POR VENCER"",SI(Y(Z4<=1,G4=$D$1,H4=""""),""CON TIEMPO"",""""))))),""ANULADA"")"
Range("AA4").Select
Selection.AutoFill Destination:=Range("AA4:A96")
Range("A4:A96").Select
Range("AA4:AA51").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("AB4").Select
Range("AB4").FormulaLocal = "=SI(K4<=2,K4,-K4)"
Range("AB4").Select
Selection.AutoFill Destination:=Range("AB4:AB96")
Range("AB4:K96").Select
Range("AB4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("AC4").Select
Range("AC4").FormulaLocal = "=SI(O4=""NO"",SI(Y(AB4<0,J4="""",H4>0),""VENCIDO SIN AUTORIZAR"",SI(Y(AB4<0,H4="""",J4=""""),""VENCIDO Y SIN AUTORIZAR EN LA I ETAPA"",SI(Y(AB4<0,J4>0),""AUTORIZADA CON VENCIMIENTO"",SI(J4>0,""AUTORIZADA SIN VENCIMIENTO"",SI(AA4=""POR VENCER"",""POR VENCER EN LA I ETAPA"",SI(AA4=""CON TIEMPO"",""CON TIEMPO EN LA I ETAPA"",SI(Y(H4>0,AB4<=1,H4=$D$1),""CON TIEMPO"",SI(AB4=2,""POR VENCER"","""")))))))),""ANULADA"")"
Range("AC4").Select
Selection.AutoFill Destination:=Range("AC4:AC96")
Range("AC4:AC96").Select
Range("AC4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("AC:AC").ColumnWidth = 40.57
Range("Z4").Select
End Sub
Esta es, lo que quiero es que aplique la formula para toda la columna aunque no haya datos, porque yo voy a pegar una tabla nueva, no voy a digitar datos, así que ya probé con otro tipo de código que solo funcionaba si yo digitaba nuevos datos a la tabla, pero en mi caso una tabla nueva se a pegar, no se digitaran datos nuevos, si no que solamente cambiara el tamaño de la tabla por el hecho de pegar una nueva. pero al hacer lo que yo hice, en la ultima foto, si me aplicaba la formula para toda la columna, pero en ese caso no tenia