0

I'm trying to clculate a formula that takes number from Column D and calcultes this number minus 14 in column C. Then, I'm triyng to autofill the range down to the first cell I calculate.

at first it was working, but now it shows me an error:

appliction-defined or object-defined error

to this line of code

Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow)

If someone would help me to solve this prblem I'll be glad.

OP_wb.Sheets("Optic Main").Activate

Dim FirstRow As Range
Dim lastrow As Range


Set FirstRow = Range("C1").End(xlDown).Offset(1, 0)
Set lastrow = Range("E1").End(xlDown).Offset(0, -2)

Range("E1").End(xlDown).Offset(0, -2).Select

            Range(FirstRow, lastrow).FormulaR1C1 = "=(c4-14)"
            Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow)

enter image description here

1 Answer 1

1

Instead of

Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow)

try

Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & lastrow.Row)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.