PDA

View Full Version : VBA Autofill Method of Range Class Failed



Jurij
08-12-2013, 02:03 AM
Hi guys,

I have a small problem with a macro in Excel. I am using the following code:


Sheet17.Range("A19:M" & Range("A19").End(xlDown).Row).ClearContents
Sheet17.Range("A18:M18").AutoFill Destination:=Sheet17.Range("A18:M" & Range("Periods") + 17), Type:=xlFillDefault

Now just to make a quick introduction. I have some calculations for products that act differently in different periods. So if the product has 3 different periods, for example, the autofill expands from Period 1 (that is the row where the original formulas are) to Period 3. Everything works fine except when the product has only 1 period. In this case the autofill shouldn't expand down but stay where it is and it seems that if it doesn't get to expand (the cell "Periods" is 1), it doesn't work.

When it comes to those products with only one period, I get an "Autofill Method of Range Class Failed" error and I have no idea how to debug this.

Any help is much appreciated

Thank you

Jurij

p45cal
08-12-2013, 02:27 AM
If Range("Periods").Value > 1 Then Sheet17.Range("A18:M18").AutoFill Destination:=Sheet17.Range("A18:M" & Range("Periods") + 17), Type:=xlFillDefault
?

Jurij
08-12-2013, 06:50 AM
It worked perfectly, thank you very much!

snb
08-12-2013, 07:49 AM
The essence of a default is it's default.
So you can omit , Type:=xlFillDefault in this code.