I have access to a spreadsheet via citrix server that links to a few useful databases (ODBC). The spreadsheet can pull up a data-table for only 1 SKU at a time. I occasionally go to this table to refresh the data for several hundred SKUs, so I wrote a looping macro that enters the SKU into the filter, refreshes that database connection and then grabs the data-table and pulls it back into my worksheet. The problem is when it it loops through the code I am receiving a run time error '1004' "this operation cannot be done because the data is refreshing in the background". This is the line of code that is hanging up is listed below:

Selection.QueryTable.Refresh BackgroundQuery:=False

I have tried to use an on error resume next statement to ignore the error, but instead of resuming the data refresh it ignores the data refresh, so that options seems to have not worked.

Any idea on how to address this error?