Home » excel » AutoFill error in excel c#

AutoFill error in excel c#

Posted by: admin April 23, 2020 Leave a comment

Questions:

The error statement says “Unable to get the AutoFill property of the Range class”. However, AutoFill property is indeed in Range Class, as I checked. Does anyone know how to resolve this error?
I have tried search in google, and there’s no approperiate answer to this. Also I have tried convert the code in VBA, and it works fine in VB.

 using Microsoft.Office.Interop.Excel;
 Application.Range["H2"].Select();
 Selection.AutoFill(Destination: mdlAMain.xlApp.Range["H2", "H" + myRow],
                                         Type: XlAutoFillType.xlFillDefault);
How to&Answers:

How big is your range? These folks had issues with >65K items. Excel AutoFill problem

A guy over here ( http://www.excelforum.com/excel-programming/734596-auto-fill-column-in-a-table.html ) mentions using what would amount to “myRow = ActiveSheet.UsedRange.Rows.Count”. That sounds like it’s a count of rows rather than an absolute cell location.

Wish I could help more. I’d stick with the “AutoFill method of Range class failed” and google the heck out of that.

Answer:

I don’t really know C# very well, but sometimes constants cannot be referred to by name outside of the particular office app that they are native to. The type parameter should not be required as it is optional inside excel.

I think the

Type: XlAutoFillType.xlFillDefault 

is causing the issue, maybe try omitting the type parameter as excel should know what to do without it.