Hi,

I have been getting a "Run-time error '1004': AutoFill method of Range class failed" on a macro. There only seems to be problems when I assign the macro to a button. When I run the macro directly everything works fine.

Here's the bit of code in question:
Worksheets("Data").Visible = xlSheetVisible
    
    Sheets("Data").Select
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("A1").Select
    Selection.AutoFill Destination:=Range("A1:A13"), Type:=xlFillDefault
    Range("A1:A13").Select
    Selection.AutoFill Range("A1:J13"), Type:=xlFillDefault
    Range("A15").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("A15").Select
    Selection.AutoFill Destination:=Range("A15:A29"), Type:=xlFillDefault
    Range("A15:A29").Select
    Selection.AutoFill Destination:=Range("A15:J29"), Type:=xlFillDefault
    Range("A15:J29").Select
    
    Worksheets("Data").Visible = xlSheetVeryHidden
It fails at line 6 where it first tries to autofill. I know that the code could be simplified, this is how Excel gave it to me when I recorded it. I have tried changing .Select to .Activate and I have tried getting rid of .Select and Selection. by merging Range and Autofill and I tried adding Sheets("Data"). before all the Range lines.

I'm new at VBA and this is pretty frustrating since it worked before I assigned to a button, so any help would be greatly appreciated.

Thanks,
Mark