RUNTIME ERROR 1004 : AUTOFILL METHOD OF RANGE CLASS FAILED

thabisothebe

New Member
Joined
Dec 21, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi, I am running into a problem with the code below, it works fine when I step through the code but when I play it using F5 I receive a runtime error 1004 :

Sub Create_Report()
Dim tbTemp As ListObject
Dim RowsTb As Long, LastRow As Long
' Start = Timer
Call Entry_Point

'create an object variable for the table inside Region Temp tab
Set tbTemp = shRegion.ListObjects("TableTemp")
RowsTb = tbTemp.DataBodyRange.Rows.Count
'Remove existing data in regional table except for line 1 if there is more thann 1 line of data
If RowsTb > 1 Then tbTemp.DataBodyRange.Rows("2:" & RowsTb).Delete
LastRow = shAll.Range("A" & Rows.Count).End(xlUp).Row
myRegion = shStart.AxRegion.Value
myDate = Format(shAll.Range("C2").Value, "YYYYMM")

shAll.Range("I2").FormulaR1C1 = "=VLOOKUP(RC[-8],MCompany,4,FALSE)"
' LastRow = shAll.Range("A" & Rows.Count).End(xlUp).Row
shAll.Range("I2").AutoFill Destination:=Range("I2:I" & LastRow)
Application.Calculate

Monthly_Sales_Reporting_Template_Tool_Start.xlsm
ABCDEFGH
1Company IDSales DocumentDocument DateCustomer codeArticle codeRejectQuantitySales Value
21030AT840302018/10/07805010414305160
31030AT840302018/10/0780501051201200
41030AT840302018/10/07805010716903450
51030AT840312018/10/08804010487010440
61030AT840312018/10/0880401077603800
71030AT840312018/10/088040110250030000
81030AT881122018/10/11804011048028800
91030AT881122018/10/11804011963039060
101030AT881122018/10/1180401201508700
111030AT881122018/10/11804011647604560
121030AT881122018/10/11804011159011800
131030AT881122018/10/11804011053031800
141030AT881122018/10/1180401092607280
Summary
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
There is too much information missing for us to troubleshoot this.
  • When it errrors out what line of code is highlighted when you go into Debug mode ?
  • What is this doing Call Entry_Point ?
  • shAll & shStart are not declared and not set
  • Does this "shStart.AxRegion" actually work, what is AxRegion ?
  • What is the activesheet ? The autofill destination is relying on shAll being the Activesheet.
 
Upvote 0
Does your "like" indicate you have resolved the issue ? In which case could you elaborate in case it helps others.
If not, do you want to reply to the questions in my previous post.
 
Upvote 0
  • When it errrors out what line of code is highlighted when you go into Debug mode ?
VBA Code:
shAll.Range("I2").AutoFill Destination:=Range("I2:I" & LastRow)
  • What is this doing Call Entry_Point ?
VBA Code:
Sub Entry_Point()
    With Application
        .StatusBar = "Your Assistant is Busy Working"
        .ScreenUpdating = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
    
    End With
End Sub


  • shAll & shStart are not declared and not set
These are sheet codes
  • Does this "shStart.AxRegion" actually work, what is AxRegion ?
Ax.Region is the drop-down selection that is the ListFillRange
  • What is the activesheet ? The autofill destination is relying on shAll being the Activesheet
?ActiveSheet.name
Start
Perhaps this is the problem when I add a line to activate "shAll" sheet it gives me an error 1004 on myRegion?
debug line becomes

Correct the sheet name shAll ("Summary" sheet) is the active sheet

Please kindly assist.
 
Last edited by a moderator:
Upvote 0
Just trying the easy one first, replace the line it is erroring out on with this and see if we are lucky.

VBA Code:
    With shAll
        .Range("I2").AutoFill Destination:=.Range("I2:I" & LastRow)
    End With
 
Upvote 0
Does your "like" indicate you have resolved the issue ? In which case could you elaborate in case it helps others.
If not, do you want to reply to the questions in my previous post.
  • When it errrors out what line of code is highlighted when you go into Debug mode ?
VBA Code:
[COLOR=rgb(65, 168, 95)]shAll.Range("I2").AutoFill Destination:=Range("I2:I" & LastRow)[/COLOR]
  • What is this doing Call Entry_Point ?
  • Just trying the easy one first, replace the line it is erroring out on with this and see if we are lucky.

    VBA Code:
        With shAll
            .Range("I2").AutoFill Destination:=.Range("I2:I" & LastRow)
        End With



Hi Alex thank you so much for your assistance?!!

I managed to solve the problem based on your observation "The autofill destination is relying on shAll being the Activesheet" . I added a line of code to activate the correct sheet before I executed the autofill method and it works just fine now:
VBA Code:
[/B][/COLOR][COLOR=rgb(0, 0, 0)][B]shAll.Activate[/B]
    shAll.Range("I2").FormulaR1C1 = "=VLOOKUP(RC[-8],MCompany,4,FALSE)"
    shAll.Range("I2").AutoFill Destination:=Range("I2:I" & LastRow)
    Application.Calculate[/COLOR][COLOR=rgb(65, 168, 95)]

[/CODE][/CODE]
VBA Code:
Sub Entry_Point()
    With Application
        .StatusBar = "Your Assistant is Busy Working"
        .ScreenUpdating = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
    
    End With
End Sub


  • shAll & shStart are not declared and not set
These are sheet codes
  • Does this "shStart.AxRegion" actually work, what is AxRegion ?
Ax.Region is the drop-down selection that is the ListFillRange
  • What is the activesheet ? The autofill destination is relying on shAll being the Activesheet
?ActiveSheet.name
Start
Perhaps this is the problem when I add a line to activate "shAll" sheet it gives me an error 1004 on myRegion?
debug line becomes

Correct the sheet name shAll ("Summary" sheet) is the active sheet

Please kindly assist.
 
Upvote 0
Can you clarify. Is it working now ?
If not is it erroring out and if so what is the error message and on what line ?
If the error is on the line myRegion = shStart.AxRegion.Value, then I need more information on what AxRegion actually is because that syntax does not make sense. Is it a Named Range and if so what is the defined range ?
 
Upvote 0
Can you clarify. Is it working now ?
If not is it erroring out and if so what is the error message and on what line ?
If the error is on the line myRegion = shStart.AxRegion.Value, then I need more information on what AxRegion actually is because that syntax does not make sense. Is it a Named Range and if so what is the defined range ?
Hi Alex

Yes its working thank you once again
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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