Refreshing table query on a protected sheet

karolina1406

Board Regular
Joined
Apr 18, 2016
Messages
108
Office Version
  1. 365
Platform
  1. Windows
I am refreshing the table query on a protected sheet. I use below code that works fine however, as soon as I add one more command to protect sheets back - i get Run time error 91: object variable or With block variable not set

VBA Code:
Dim wSheet As Worksheet
For Each wSheet In Worksheets
wSheet.Unprotect Password:="password"
Next wSheet
Application.ScreenUpdating = False
Sheets("Available_Stock").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False

Any ideas why??
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Watch MrExcel Video

Forum statistics

Threads
1,114,663
Messages
5,549,292
Members
410,908
Latest member
Allen P
Top