thabisothebe
New Member
- Joined
- Dec 21, 2021
- Messages
- 5
- Office Version
- 365
- Platform
- 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
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Company ID | Sales Document | Document Date | Customer code | Article code | Reject | Quantity | Sales Value | ||
2 | 1030AT | 84030 | 2018/10/07 | 8050 | 104 | 1 | 430 | 5160 | ||
3 | 1030AT | 84030 | 2018/10/07 | 8050 | 105 | 120 | 1200 | |||
4 | 1030AT | 84030 | 2018/10/07 | 8050 | 107 | 1 | 690 | 3450 | ||
5 | 1030AT | 84031 | 2018/10/08 | 8040 | 104 | 870 | 10440 | |||
6 | 1030AT | 84031 | 2018/10/08 | 8040 | 107 | 760 | 3800 | |||
7 | 1030AT | 84031 | 2018/10/08 | 8040 | 110 | 2 | 500 | 30000 | ||
8 | 1030AT | 88112 | 2018/10/11 | 8040 | 110 | 480 | 28800 | |||
9 | 1030AT | 88112 | 2018/10/11 | 8040 | 119 | 630 | 39060 | |||
10 | 1030AT | 88112 | 2018/10/11 | 8040 | 120 | 150 | 8700 | |||
11 | 1030AT | 88112 | 2018/10/11 | 8040 | 116 | 4 | 760 | 4560 | ||
12 | 1030AT | 88112 | 2018/10/11 | 8040 | 111 | 590 | 11800 | |||
13 | 1030AT | 88112 | 2018/10/11 | 8040 | 110 | 530 | 31800 | |||
14 | 1030AT | 88112 | 2018/10/11 | 8040 | 109 | 260 | 7280 | |||
Summary |