Hi ppz,
i'm trying to use 2 cell references to form a range selection to autofill in a formula.
The 2 cells are simply the 1st data cell & last data cell in a column. I want to enter a formula in the 1st cell & have a bit of VBA autofill the rest of the column. I created a macro to see the code when i manually do this. It creates a code usiong the Selection.Autofill command being used. When i try to use this with my code i get an error. Error i get states 'Autofill Method Of Range Class Failed'.
I'm not sure what i'm doing wrong but my code is below:
TO_WORKSHEET is the worksheet i am using
strFormula is the formula string created
strFormulaRangeValue is the range to select for the autofill of the formula
intLastRowCount is a count of the last row with data in it.
Range(MyFind(ActiveWorkbook.Worksheets(TO_WORKSHEET), CStr(varFirstCellValue))).Select
strFormula = Mid(strFormula, 1, Len(strFormula) - 2) 'get rid of extra + in the formula
Range(ActiveCell.Offset(1, 0).Address).Select
ActiveCell.FormulaR1C1 = "=SUM(" & strFormula & ")"
strFormulaRangeValue = ActiveCell.Offset(1, 0).Address & ":" & ActiveCell.Offset(intLastRowCount - 6, 0).Address
Range(ActiveCell.Address).Select
Selection.AutoFill Destination:=Range(strFormulaRangeValue), Type:=xlFillDefault
Range(strFormulaRangeValue).Select
Please could you help with this issue? If you know of a better method of using VBA to autofill in columns then please let me know.
Thanks,
Shuja
Bookmarks