Hi all,
I am trying to autofill a range in which the Row number of the "end of range" cell (i.e. 25 in my first code) is specified by a variable.
I got my code working for a specified range (C15:C25):
Now, I want the row number of the range end to be specified according to the value of the variable totalrows.
I tried to do it like following, however, I get an "Autofill method of Range class failed" error.
Any help will be much appreciated.
I am trying to autofill a range in which the Row number of the "end of range" cell (i.e. 25 in my first code) is specified by a variable.
I got my code working for a specified range (C15:C25):
Code:
ActiveCell.FormulaR1C1 = _
"=IF(R7C1=""Method 1"",RC[-1]-R[1]C[-1],R[1]C[-1]-RC[-1])"
Range("C15").Select
Selection.AutoFill Destination:=Range("C15:C25"), Type:=xlFillDefault
Range("C15:C25").Select
Now, I want the row number of the range end to be specified according to the value of the variable totalrows.
I tried to do it like following, however, I get an "Autofill method of Range class failed" error.
Code:
totalrows_int = 30
ActiveCell.FormulaR1C1 = _
"=IF(R7C1=""Method 1"",RC[-1]-R[1]C[-1],R[1]C[-1]-RC[-1])"
Range("C15").Select
Selection.AutoFill Destination:=Range(Cells(3, 15), Cells(3, totalrows)), Type:=xlFillDefault
Range(Cells(3, 15), Cells(3, totalrows)).Select
Any help will be much appreciated.