Thanks Thanks:  0
Likes Likes:  0
Results 1 to 6 of 6

Thread: on error goto issue

  1. #1
    Board Regular
    Join Date
    Aug 2008
    Posts
    295
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default on error goto issue

    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

  2. #2
    Moderator mole999's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    9,093
    Post Thanks / Like
    Mentioned
    10 Post(s)
    Tagged
    1 Thread(s)

    Default Re: on error goto issue

    show the rest of your code, atleast from where the loop starts, or the whole routine
    • Yes I know there are better ways to do it. I just wish I knew them. - 2003, 2007, 2010, 2013 & 2016
    • I wear my ignorance openly, excel is not my chosen career, its a means to an ends
    • Posting Guidelines Want to post well laid out questions and answers Translate Excel Versions
      Code:
      [CODE ]Put Your Code[/ CODE]
    • Settings > General Settings (on the left) scroll to the bottom, > Miscellaneous Options > Use ENHANCED
    • X-Posting Guidelines Rule 13 > CHART STUFF

  3. #3
    Board Regular
    Join Date
    Aug 2008
    Posts
    295
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: on error goto issue

    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

  4. #4
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,351
    Post Thanks / Like
    Mentioned
    25 Post(s)
    Tagged
    3 Thread(s)

    Default Re: on error goto issue


  5. #5
    Board Regular
    Join Date
    Aug 2008
    Posts
    295
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: on error goto issue

    but the sollution is not clear

  6. #6
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,351
    Post Thanks / Like
    Mentioned
    25 Post(s)
    Tagged
    3 Thread(s)

    Default Re: on error goto issue

    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

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •