On Error Resume Next

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,057
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code which is all good.
VBA Code:
On Error Resume Next
Call HistoricalRawData

On Error Resume Next
Call SkillDailyRawData

This is the other code which checks the conditions in the sheet.
1) The 1st code works well if the sheet is not available which is perfect
2) But if the sheet is available then it should check the conditions (code 2)


Code:
Sub HistoricalRawData()
Sheets("Historical All Fields Raw Data ").Select
If ActiveSheet.Range("I2").Value <> "Longest Queued" Then
MsgBox "Incorrect Raw file selected for Historical All Fields Raw Data" & vbNewLine & vbNewLine & "Please Check the Historical All Fields Raw Data Raw file and Download the file again", vbCritical, "Historical All Fields Raw Data"
Sheets(Array("Historical All Fields Raw Data ")).Select
    Sheets("Historical All Fields Raw Data ").Activate
   Application.DisplayAlerts = False
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
Sheets("Report").Select
Exit Sub
End If
End sub

Sub SkillDailyRawData()
Sheets("Skill Daily Historical V1.0-Ski").Select
If ActiveSheet.Range("E2").Value <> "Handle Time" Then
MsgBox "Incorrect Raw file selected for Skill Daily Raw Data" & vbNewLine & vbNewLine & "Please Check the Skill Daily Raw Data and Download the file again", vbCritical, "Skill Daily Raw Data"
Sheets(Array("Skill Daily Historical V1.0-Ski")).Select
    Sheets("Skill Daily Historical V1.0-Ski").Activate
   Application.DisplayAlerts = False
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
Sheets("Report").Select
Exit Sub
End If
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try removing "On Error Resume Next" and step through the code via F8 to see where the error is occurring.
 
Upvote 0
Try removing "On Error Resume Next" and step through the code via F8 to see where the error is occurring.
Did that,
I think I did not explain the concern.

first code is need as if the sheet Historical All Fields Raw Data is not available in the workbook is all perfect.
But if the sheet Historical All Fields Raw Data is available then it will process and if any code 2. but in case there is any mismatch in code 2, then it should display the msg.

Currently as the 1 st code is states then "On Error Resume Next", this will effect the non execution of the code2 with out displaying the msg to the user.

So if the sheet Historical All Fields Raw Data is available then the code should ignore "On Error Resume Next".
But if the sheet Historical All Fields Raw Data is not available then the should consider "On Error Resume Next"

I hope now it is clear. as what is needed.
 
Upvote 0
The MsgBox won't be executed when this if statement is not true :
VBA Code:
If ActiveSheet.Range("E2").Value <> "Handle Time" Then
Step though to see whether the statement is true or not.

It should not make a difference but you could try:
VBA Code:
On Error Resume Next
Call HistoricalRawData
On Error GoTo 0
On Error Resume Next
Call SkillDailyRawData
 
Upvote 0
The MsgBox won't be executed when this if statement is not true :
VBA Code:
If ActiveSheet.Range("E2").Value <> "Handle Time" Then
Step though to see whether the statement is true or not.

It should not make a difference but you could try:
VBA Code:
On Error Resume Next
Call HistoricalRawData
On Error GoTo 0
On Error Resume Next
Call SkillDailyRawData
great, worked.
Completely missed the On Error goto 0. :biggrin:
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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