VBA to stop further processes if a Query has any errors

johnny51981

Active Member
Joined
Jun 8, 2015
Messages
366
I'm working on updating some reports with VBA to allow for less hands on. Essentially, after I've acquired my source data in CSV format, I have a single button that refreshes the appropriate queries that update through PQ.

Now, to make sure I haven't mucked anything up or if there is anything wrong with the source data, what would be the appropriate VBA to notify me of an error in the query and to stop any further processes, such as my saving with the queries removed to the final landing spot for distribution?

EDIT:
Another scenario came to me. What would be the VBA that would provide me a notification of errors in a query but allows me to allow it to continue if I choose? One of my data sources has a mixed use column that may or may not have errors in it.
 
Last edited by a moderator:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Have you taken a look at this site for error handling strategies?

 
Upvote 0
Oh. I missed that in your problem discussion. What are the errors that you are receiving?
 
Upvote 0
I don't receive them all of the time, so this is a preventative measure. The Power Queries (listed in Queries and Connections) can sometimes have errors due to formatting or I've messed something up along the way (such as the wrong file being saved with the wrong CSV file name).
 
Upvote 0
One thing that I learned is that the data type has to be consistent both in the query and the spreadsheet. Are you familiar with changing the data type in the query editor?
 
Upvote 0
Yes, very familiar. That is not the issue and the Power Query template is solid. The issue is to catch when mistakes happen to keep the report from finalizing.

Example:
Yesterday: Refreshed report, all came back clean with no errors, VBA allows report to complete and save as and where needed. Successfully complete.
Today: Two CSV Datasets were misnamed (One is named Two/Two is Named One), Refreshed report, resulting in errors. Desired result is to stop any further VBA from executing and report not saved as and where needed.
 
Upvote 0
That seems like it would need to be configured in M Code to catch the errors while processing the query, which unfortunately is above my pay grade.
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

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