I use the same autofill code all my other macros. The difference with this macro is that I implemented an Input box earlier in the code for a different function. I think I am having an issue with what cell should be used to autofill the other cells.
I keep getting a "This operation will cause some merged cells to unmerge. Do you wish to continue?" message but I already unmerged the entire sheet earlier in the code. Then VBA gives me an error: "Run-time error '1004': AutoFill method of Range class failed."
The correct function should use the cell "ActiveCell.Offset(rowOffset:=2, columnoffset:=13).Activate" as the data to auto fill down the column.
Any help would be appreciated.
*Edited to include successful code
Sub Macro1()
'
' Macro to cut/paste input row and autofill formula in column N
'
Dim myValue As Variant
myValue = InputBox("Select Row to Move", "Input", (""))
Dim sh As Worksheet, lastrow As Long
Set sh = ActiveSheet
If myValue = "" Then Exit Sub
'Unmerge sheet'
Cells.Select
Selection.UnMerge
'Select Input row, cut/paste
Rows(myValue).Select
Selection.Cut
ActiveCell.Offset(rowoffset:=-1).Activate
Selection.Insert Shift:=xlDown
'select cell in column N to input formula
ActiveCell.Offset(rowoffset:=2, columnoffset:=13).Activate
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=+RC[-2]-RC[-1]"
'autofill cell down to last used row
lastrow = sh.Range("B" & Rows.Count).End(xlUp).Row
Range(Cells(ActiveCell.Row, ActiveCell.Column), Cells(lastrow, ActiveCell.Column)).FormulaR1C1 = "=+RC[-2]-RC[-1]"
End Sub