Question about - On Error GoTo

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
217
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

Not sure where what I am missing here, I am trying to use On Error GoTo to show a msg: The File is closed, please open it before running the macro, However, even when the file is opened the macro keep showing the error. I am adding the Erro GoTo righ before the error line. Is that correct?

On Error GoTo Label:
Set CurrWkWB = Workbooks("WTD Sales VS Demand Tracker_W" & CurrWk & "_" & WeekdayName(Weekday(Date), True, vbSunday) & ".XLSM")
CurrWkWB.Activate

Label:
MsgBox ("Keep both files (Current and Next Week) opened before running the Macro"), vbExclamation
Exit Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I assume when you say "keep showing the error" you mean your MessageBox. The problem is you have the "Exit Sub" statement in the wrong location... it needs to be placed before the MessageBox statement, not after it, otherwise even properly running code will move down to the MessageBox statement... the "Exit Sub" stops that from happening.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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