Link to home
Start Free TrialLog in
Avatar of Shanan212
Shanan212Flag for Canada

asked on

Autofill method of range class failed error

Private Function FormulaFiller(idata As String, iStart As String, iend As String)
    
    Dim rgCopy As Range, rgDelete As Range, rgFill As Range, rgClear As Range
    
    Set rgCopy = Evaluate(iStart & ":" & iend)     'Formulas in these cells will be copied down
    Set rgFill = Evaluate(idata)        'First piece of raw data
    
    Set rgFill = Range(rgFill, rgFill.Worksheet.Cells(Rows.count, rgFill.Column).End(xlUp))  'All data in that column
    Set rgFill = rgCopy.Resize(rgFill.Rows.count)       'Fill formulas down in this range
    
    
    Set rgDelete = rgCopy.Offset(1, 0).Resize(rgCopy.Worksheet.UsedRange.Rows.count)
    rgDelete.ClearContents
    rgFill.SpecialCells(xlCellTypeFormulas).Interior.Color = RGB(237, 237, 4)
    rgCopy.AutoFill rgFill, xlFillCopy
    Application.CutCopyMode = False

End Function

Open in new window


The above function get called by:

Call FormulaFiller("A3", "N3", "Q3")

Hi,

The problem I am having is that, this works if there are multiple lines of raw data (from say A3:M20) and I am trying to pull down formulas from rows N3:Q3

But when I have a single line of raw data only populating from A3 to M3, the function gives me ‘Autofill method of range class failed’ error.

Is there a way to skip the function if only row A3:M3 is populated?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shanan212

ASKER

Thanks! Wasnt thinking of that :/