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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
show the rest of your code, atleast from where the loop starts, or the whole routine
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,938
Latest member
Aaliya13

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