How do I keep macro running after running this piece of code?

z3115

Board Regular
Joined
Nov 1, 2013
Messages
71
Hi All,

I have the following macro, which I did not write myself. It works perfectly, but now I want to add in some additional steps after this code finishes running. The problem is that Excel seems to just ignore everything I put after this piece. Any idea why?

Code:
    Dim wsName As String
    Dim RangeError As Boolean
    '--------------------------------
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error GoTo NoEssbaseRange
    '- main loop
    For Each ws In Worksheets
        wsName = ws.Name
        RangeError = False
        Application.GoTo Reference:=ws.range("_essbase")
        If Not RangeError Then Application.Run Macro:="EssMenuRetrieve"
    Next
    On Error GoTo 0
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    Exit Sub
    '------------------------------------------------------------------
    '- handle the Excel error produced when the range does not exist
    '- comment out the MsgBox line unless you need to see each one
NoEssbaseRange:
    'MsgBox ("Worksheet '" & wsName & "' has no essbase range.")
    RangeError = True   ' stops retrieve running in the next line above
    Resume Next         ' keep the macro running
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Exit Sub

After that statement, the macro quits. Any code you want to add has to go before that statement is called. Just put it directly above that line.
 
Upvote 0
OK that makes sense, doing that appears to mess up the original piece of code though, and gives me an error. Any thoughts? Thanks!
Code:
Exit Sub

After that statement, the macro quits. Any code you want to add has to go before that statement is called. Just put it directly above that line.
 
Upvote 0
you will need to show us what you added.
 
Upvote 0
you will need to show us what you added.

Here's the piece I pasted first along with everything after it (as you can see I have 2 different variations of the original piece):

Code:
'Run the first Hyperion Retrieval
    Dim wsName As String
    Dim RangeError As Boolean
    '--------------------------------
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error GoTo NoEssbaseRange
    '- main loop
    For Each ws In Worksheets
        wsName = ws.Name
        RangeError = False
        Application.GoTo Reference:=ws.range("_essbase")
        If Not RangeError Then Application.Run Macro:="EssMenuRetrieve"
    Next
    On Error GoTo 0
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    'Exit Sub
    '------------------------------------------------------------------
    '- handle the Excel error produced when the range does not exist
    '- comment out the MsgBox line unless you need to see each one
NoEssbaseRange:
    'MsgBox ("Worksheet '" & wsName & "' has no essbase range.")
    RangeError = True   ' stops retrieve running in the next line above
    'Resume Next         ' keep the macro running


'Part 2
Sheets("Show Details 2").Cells.ClearContents
Sheets("NIE-ALL").Cells.Copy
Sheets("Show Details 2").range("A1").PasteSpecial
Application.CutCopyMode = False


Sheets("Show Details").Select
    range("A3").Select
range(selection, selection.End(xlDown)).Copy
Sheets("Show Details 2").range("B2").PasteSpecial Transpose:=True


'Run the 2nd Hyperion retrieval
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error GoTo NoEssbaseRange
    '- main loop
    For Each ws In Worksheets
        wsName = ws.Name
        RangeError = False
        Application.GoTo Reference:=ws.range("_essbase2")
        If Not RangeError Then Application.Run Macro:="EssMenuRetrieve"
    Next
    On Error GoTo 0
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    'Exit Sub
    '------------------------------------------------------------------
    '- handle the Excel error produced when the range does not exist
    '- comment out the MsgBox line unless you need to see each one
'NoEssbaseRange:
    'MsgBox ("Worksheet '" & wsName & "' has no essbase range.")
    RangeError = True   ' stops retrieve running in the next line above
    Resume Next         ' keep the macro running
    
Sheets("FHolder").Visible = False 'Hide the support tabs
Sheets("TO-ALL").Visible = False
Sheets("NIE-ALL").Visible = False


Sheets("Show Details 2").Select


Exit Sub






End Sub

If anyone can help I would be extremely grateful, thank you!
 
Upvote 0
you cannot just comment out the exit sub. it then falls into the error handler.

You can try this:

Code:
'Run the first Hyperion Retrieval    Dim wsName As String
    Dim RangeError As Boolean
    '--------------------------------
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error GoTo NoEssbaseRange
    '- main loop
    For Each ws In Worksheets
        wsName = ws.Name
        RangeError = False
        Application.GoTo Reference:=ws.range("_essbase")
        If Not RangeError Then Application.Run Macro:="EssMenuRetrieve"
    Next
    On Error GoTo 0
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
'Part 2
Sheets("Show Details 2").Cells.ClearContents
Sheets("NIE-ALL").Cells.Copy
Sheets("Show Details 2").range("A1").PasteSpecial
Application.CutCopyMode = False




Sheets("Show Details").Select
    range("A3").Select
range(selection, selection.End(xlDown)).Copy
Sheets("Show Details 2").range("B2").PasteSpecial Transpose:=True




'Run the 2nd Hyperion retrieval
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error GoTo NoEssbaseRange
    '- main loop
    For Each ws In Worksheets
        wsName = ws.Name
        RangeError = False
        Application.GoTo Reference:=ws.range("_essbase2")
        If Not RangeError Then Application.Run Macro:="EssMenuRetrieve"
    Next
    On Error GoTo 0
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    
Sheets("FHolder").Visible = False 'Hide the support tabs
Sheets("TO-ALL").Visible = False
Sheets("NIE-ALL").Visible = False




Sheets("Show Details 2").Select
   
    Exit Sub
    '------------------------------------------------------------------
    '- handle the Excel error produced when the range does not exist
    '- comment out the MsgBox line unless you need to see each one
NoEssbaseRange:
    'MsgBox ("Worksheet '" & wsName & "' has no essbase range.")
    RangeError = True   ' stops retrieve running in the next line above
    'Resume Next         ' keep the macro running




End Sub
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,903
Members
449,132
Latest member
Rosie14

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