AutoFill Macro

I want to create a column in P called Age of Ticket. It calculates two dates, and then autocomplete. This macro will be used for reports that change the number of rows. When I use this, it mainly performs calculations on P2, then it calculates on P1 (where is the label) and is not autocomplete.

Dim LastRow As Long

LastRow = Range("P65000").End(xlUp).Row

Range("P1").Select
ActiveCell.FormulaR1C1 = "Age of Ticket"
Range("P2").Select
ActiveCell.FormulaR1C1 = "=RC[-5]-RC[-8]"
Range("P2").Select
Selection.AutoFill Destination:=Range("P2:P" & LastRow)
Range("P2:P3000").Select
ActiveWindow.SmallScroll Down:=210

[Results]

enter image description here

+4
source share
1 answer

, , , . , , P65000 ctrl - upArrow. , P1 , LastRow = 1. , P2: P1. , . K, .

. .Select. . .Select

.FormulaR1C1 .

:

Dim LastRow As Long

 LastRow = Range("K65000").End(xlUp).Row

Range("P1").value = "Age of Ticket"
Range("P2:P" & LastRow).FormulaR1C1 = "=RC[-5]-RC[-8]"

, , r1c1.

Range("P2").Formula = "=K2-H2"
Range("P2").AutoFill Destination:=Range("P2:P" & LastRow)

, .

+5

Source: https://habr.com/ru/post/1616409/


All Articles