AutoFill method of Range class failed

Geshwinn

New Member
Joined
Nov 4, 2010
Messages
24
Hi guys,

This is the code:

Code:
Sub calcWeb()
Dim FinalRow As Long
Dim FinalColumn As Long


With Sheets("Web")
FinalRow = .Cells(Rows.Count, 3).End(xlUp).Row
FinalColumn = .Cells(1, Columns.Count).End(xlToLeft).Column

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "OK/ERROR"
.Cells(2, 1).FormulaR1C1 = "=IF((COUNTBLANK(RC[1])+COUNTBLANK(RC[9]:RC[21]))=0, 0, 1)"
.Cells(2, 1).AutoFill Destination:=Range("A2:A" & FinalRow)

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "Empty Attributes"
.Cells(2, 1).FormulaR1C1 = "=COUNTBLANK(RC[2])+COUNTBLANK(RC[10]:RC[22])"
.Cells(2, 1).AutoFill Destination:=Range("A2:A" & FinalRow)

End With
Call calcApp
End Sub

Sub calcApp()
Dim FinalRow As Long
Dim FinalColumn As Long

With Sheets("Application")
FinalRow = .Cells(Rows.Count, 3).End(xlUp).Row
FinalColumn = .Cells(1, Columns.Count).End(xlToLeft).Column

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "OK/ERROR"
.Cells(2, 1).FormulaR1C1 = "=IF(COUNTBLANK(RC[8]:RC[23])=0, 0, 1)"
[COLOR="Red"].Cells(2, 1).AutoFill Destination:=Range("A2:A" & FinalRow)[/COLOR]

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "Empty Attributes"
.Cells(2, 1).FormulaR1C1 = "=COUNTBLANK(RC[9]:RC[24])"
.Cells(2, 1).AutoFill Destination:=Range("A2:A" & FinalRow)

End With
'Call calcDatabase
End Sub

When I run it it stops at this row and says "autofill method of range class failed" but when I run the macros separately, one by one, everything works perfectly.

What could be wrong here?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I think you need to put . dots in front of range because without them it would be working on the activesheet which may not be the same as the sheet you are trying to autofill:

Rich (BB code):
Sub calcWeb()
Dim FinalRow As Long
Dim FinalColumn As Long


With Sheets("Web")
FinalRow = .Cells(Rows.Count, 3).End(xlUp).Row
FinalColumn = .Cells(1, Columns.Count).End(xlToLeft).Column

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "OK/ERROR"
.Cells(2, 1).FormulaR1C1 = "=IF((COUNTBLANK(RC[1])+COUNTBLANK(RC[9]:RC[21]))=0, 0, 1)"
.Cells(2, 1).AutoFill Destination:=.Range("A2:A" & FinalRow)

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "Empty Attributes"
.Cells(2, 1).FormulaR1C1 = "=COUNTBLANK(RC[2])+COUNTBLANK(RC[10]:RC[22])"
.Cells(2, 1).AutoFill Destination:=.Range("A2:A" & FinalRow)

End With
Call calcApp
End Sub

Sub calcApp()
Dim FinalRow As Long
Dim FinalColumn As Long

With Sheets("Application")
FinalRow = .Cells(Rows.Count, 3).End(xlUp).Row
FinalColumn = .Cells(1, Columns.Count).End(xlToLeft).Column

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "OK/ERROR"
.Cells(2, 1).FormulaR1C1 = "=IF(COUNTBLANK(RC[8]:RC[23])=0, 0, 1)"
.Cells(2, 1).AutoFill Destination:=.Range("A2:A" & FinalRow)

.Cells(1, 1).EntireColumn.Insert
.Cells(1, 1).Value = "Empty Attributes"
.Cells(2, 1).FormulaR1C1 = "=COUNTBLANK(RC[9]:RC[24])"
.Cells(2, 1).AutoFill Destination:=.Range("A2:A" & FinalRow)

End With
'Call calcDatabase
End Sub
 
Upvote 0
Glad it worked, it is sometimes hard to remember all the little dots and so forth.
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,872
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top