Macro - Run Time 91 Error

LottieRoseC

New Member
Joined
May 24, 2012
Messages
1
Macro - Run Time 91 Error
Hi,

I have an excel document that is linked to access, and a macro runs to refresh all of the links and the pivots in excel that run off the data. My spreadsheet was working fine, and refreshing, but now when I run the Macro to refresh everything I get a Run Time error 91 Object Variable or With Block Variable not set. If I go to debug it highlights the following part of the code

Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False

I have checked that all the tables will refresh manually (which they do) and the connections all work. Does anyone know what the problem is?

Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi and Welcome to the Board,

What is the code that comes before the line of code that you posted?

If "Selection" hasn't been set to an Object that has as a ListObject, then you could get that error. This might have happened if you recorded a macro by clicking on the Table at Cell A1, then later moved the Table to Cell A2.

Typically it's better to avoid the use of Selection and reference the Objects directly by Name or Index.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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