Allow using Named Ranges of protected sheet as data source in pivot

acmehra

New Member
Joined
Jan 20, 2018
Messages
16
Hi Friends ,

I am using named ranges as data source in pivot. These named ranges can be selected by user from a combobox. I change data source of the pivot on the basis of named range selected from combobox.
My code works fine if the sheet of the selected name range in combobox is unprotected.

To make my code work I tried to unprotect the worksheet in code and then protect at the end . A Part of my code is :

HTML:
Sub ChangeSellDataSource()
With ActiveSheet.Shapes("DD_Sell").ControlFormat
   dd_val = .List(.ListIndex)
   Sheets(dd_val).Unprotect     Set Data_sht = ThisWorkbook.Worksheets(dd_val)  Set Pivot_sht = ThisWorkbook.Worksheets("reports")

Here DD_Sell is my combobox name . It contains the list of named ranges. I have named the ranges same as of worksheet name. For example if the work sheet name is "Sell" then named range is "Sell". "Reports" is the worksheet on which pivot exists.

Please help. This code give error Ïnvalid Procedure or argument". But if the data source sheet is unprotected and I remove unprotect code statement then it works fine.

I tried allowing use of "Locked cells in pivottable"" while protecting sheet but it also doesn't help. So I guess unprotecting the worksheet in the code is the only way out.
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

acmehra

New Member
Joined
Jan 20, 2018
Messages
16
System give run time error : 5 invalid procedure or argument on adding unprotect statement
 

Forum statistics

Threads
1,136,260
Messages
5,674,681
Members
419,520
Latest member
Jennifer4Dillon

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
Top