on error goto issue

Leske

Active Member
Joined
Aug 26, 2008
Messages
297
Hello i have the following code:
Code:
On Error GoTo Fout4
Sheets("Bev - MTD").Select
 Range("A1").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Month2").CurrentPage = CurrentMonth
   
Fout4:
this code sit's in a for "i = 1 to 10"

The first time whenever he doesn't find the sheets("Bev - MTD") he goes to Fout4:
But the next file he opens and there isn't sheets("Bev - MTD") he gots stuck.

Don't really see the problem?
Is it because it can only have once that error and can't go to Fout4 because it is in a "i = 1 to 10"?


Why does it work for one file but not for the others?

Kind regards,

Les
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,879
show the rest of your code, atleast from where the loop starts, or the whole routine
 

Leske

Active Member
Joined
Aug 26, 2008
Messages
297
Code:
Sheets("Marcel").Select
lr2 = Range("A2").End(xlDown).Row
For j = 2 To lr2
Windows("list of sending items.xlsx").Activate
Sheets("Marcel").Select
Klant = Cells(j, 1).Value
KlantOpen = Cells(j, 2).Value

KlantFileName = Cells(j, 3).Value

Workbooks.Open Filename:=BIBOpath
Sheets("Data").Select
ActiveSheet.Range("a:ar").AutoFilter Field:=1, Criteria1:="BELGIUM"

Windows(BIBOwindows).Activate
'Windows("new BI BO OOH 2016.xlsm").Activate
Sheets("Data").Select
Range("A1").Select


ActiveSheet.ShowAllData
ActiveSheet.Range("a:ar").AutoFilter Field:=37, Criteria1:=Klant

Workbooks.Open Filename:=KlantOpen


Sheets("Data").Visible = True
Sheets("Data").Select
Range("A1").Select
Cells.Select
    Selection.Delete
    
Windows(BIBOwindows).Activate
 'Windows("new BI BO OOH 2016.xlsm").Activate


 Cells.Select
      Selection.Copy
      
Windows(KlantFileName).Activate
    Range("a1").Activate
    ActiveSheet.Paste
'Application.CutCopyMode = False

 Cells.Select
  Selection.ClearFormats


CurrentMonth = Month(Date) - 1
CurrentYear = Year(Date)

On Error GoTo Fout3
Sheets("Food - MTD").Select
 Range("A1").Select
    ActiveSheet.PivotTables("PivotTable7").PivotFields("Month2").CurrentPage = CurrentMonth
   
Fout3:
   
On Error GoTo Fout4
Sheets("Bev - MTD").Select
 Range("A1").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Month2").CurrentPage = CurrentMonth
   
Fout4:

ActiveWorkbook.RefreshAll

Sheets("Data").Select
ActiveWindow.SelectedSheets.Visible = False
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,178
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Since it looks like you just want to ignore errors, replace this:
Code:
On Error GoTo Fout3
Sheets("Food - MTD").Select
 Range("A1").Select
    ActiveSheet.PivotTables("PivotTable7").PivotFields("Month2").CurrentPage = CurrentMonth
   
Fout3:
   
On Error GoTo Fout4
Sheets("Bev - MTD").Select
 Range("A1").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Month2").CurrentPage = CurrentMonth
   
Fout4:
with this:
Code:
On Error Resume Next
Sheets("Food - MTD").PivotTables("PivotTable7").PivotFields("Month2").CurrentPage = CurrentMonth
Sheets("Bev - MTD").PivotTables("PivotTable1").PivotFields("Month2").CurrentPage = CurrentMonth
On Error Goto 0
 

Forum statistics

Threads
1,078,252
Messages
5,339,100
Members
399,278
Latest member
randomNumberGenerator2211

Some videos you may like

This Week's Hot Topics

Top