Como hacer el Selection.AutoFill Destination:=Range variable
Me estoy iniciando con las macros y el problema que me surgió fue que realizo un autofill para pegar una fórmula hacia abajo, pero el rango se queda fijo, y yo necesito que el rango se quede abierto, ya que la macro la aplicaría en archivos cuyo formato es el mismo, pero el numero de celdas hacia abajo varia, ¿cómo lo puedo hacer?
Sub Macro1()
'
' Macro1 Macro
'
'
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 4), Array(10, 4), Array(11, 4), Array(12, 4), Array(13, 1 _
), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), _
Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array( _
33, 1), Array(34, 1), Array(35, 1), Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), _
Array(40, 1), Array(41, 1), Array(42, 1), Array(43, 1), Array(44, 1), Array(45, 1)), _
TrailingMinusNumbers:=True
Columns("A:A"). EntireColumn. AutoFit
Columns("B:B"). EntireColumn. AutoFit
Columns("C:C").ColumnWidth = 10.57
Columns("C:C"). EntireColumn. AutoFit
Columns("D:D"). EntireColumn. AutoFit
Columns("F:F"). EntireColumn. AutoFit
Columns("G:G"). EntireColumn. AutoFit
Columns("H:H"). EntireColumn. AutoFit
Dim fila As String
Range("E2").End(xlDown).Select
lista = Selection.Cells(1, 1).Address
Rows("2:2").Select
Selection.AutoFilter
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("H:H").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("P:P").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D3").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1],3)"
Range("D3").Select
Selection.AutoFill Destination:=Range("D3" & ":" & "D" & fila)
Range("D3:D13816").Select
Range("G3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],base.xlsm!cc,4,0)"
Range("G3").Select
Selection.AutoFill Destination:=Range("G3" & ":" & "G" & fila)
Range("G3:G13816").Select
Range("H3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-6],base.xlsm!cuentas,8,0)"
Range("H3").Select
Selection.AutoFill Destination:=Range("H3" & ":" & "H" & fila)
Range("H3:H13816").Select
Range("P3").Select
ActiveCell.FormulaR1C1 = "=DATEDIF(RC[-1],TODAY(),""d"")"
Range("P3").Select
Selection.AutoFill Destination:=Range("P3" & ":" & "P" & fila)
Range("P3:P13816").Select
Columns("P:P").Select
Selection.NumberFormat = "General"
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 17
ActiveWindow.ScrollColumn = 18
ActiveWindow.ScrollColumn = 19
ActiveWindow.ScrollColumn = 20
ActiveWindow.ScrollColumn = 21
ActiveWindow.ScrollColumn = 22
ActiveWindow.ScrollColumn = 23
ActiveWindow.ScrollColumn = 24
ActiveWindow.ScrollColumn = 25
ActiveWindow.ScrollColumn = 26
ActiveWindow.ScrollColumn = 27
ActiveWindow.ScrollColumn = 28
ActiveWindow.ScrollColumn = 29
ActiveWindow.ScrollColumn = 30
ActiveWindow.ScrollColumn = 31
ActiveWindow.ScrollColumn = 32
ActiveWindow.ScrollColumn = 33
ActiveWindow.ScrollColumn = 34
Range("AW3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],base.xlsm!compania,2,0)"
Range("AW3").Select
Selection.AutoFill Destination:=Range("AW3:AW13816")
Range("AW3:AW13816").Select
ActiveWindow.ScrollColumn = 32
ActiveWindow.ScrollColumn = 31
ActiveWindow.ScrollColumn = 30
ActiveWindow.ScrollColumn = 29
ActiveWindow.ScrollColumn = 28
ActiveWindow.ScrollColumn = 27
ActiveWindow.ScrollColumn = 26
ActiveWindow.ScrollColumn = 24
ActiveWindow.ScrollColumn = 23
ActiveWindow.ScrollColumn = 21
ActiveWindow.ScrollColumn = 19
ActiveWindow.ScrollColumn = 17
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
End Sub