VBA Refresh of Data Model - How to detect an error

LGXSteve

New Member
Joined
Sep 1, 2015
Messages
7
I have written a small bit of VBA to allow me to have a button on the front worksheet to refresh the Data Model.

The code looks like this;

Sub Button2_Click()
ActiveWorkbook.Model.Refresh
End Sub

There are occasions where a fault in the data means that this will fail. if I do the refresh through the 'Manage' Screen I can see the error, and correct it.

Is there anyway of detecting if the above has failed, and at least alert the user there was a problem?

(Arguably the data should not be able to get into a state which would cause this to fail, but it does. Detecting the error, and manually fixing it is probably an easier solution for the time being).

Thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Finally I can solve a multi-year old request in the hope it may sometime help someone like so many other posts have helped me.

Sheet.Unprotect 'Important otherwise the refresh table will not work if it is a protected sheet
Sheet.PivotTable(1).RefreshTable

This will produce the same error message that you get when refreshing a pivot table manually that is linked to a data model. Just add this for anyone of your tables linked to the data model, no need to run it for all.
 
Upvote 1

Forum statistics

Threads
1,223,639
Messages
6,173,496
Members
452,516
Latest member
druck21

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