Unprotecting macro button in a protected sheet

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
I have made a sheet that I have to give access to other users as well. But I have protected cells in the sheet so that the formulas can not be altered. But when I do this, macro button stop responding. In fact, they become unclickable. I tried moving the buttons to the unprotected cells but as the macro is working on the part of sheet which is protected, so it is not working.
I want user to be able to click on macro button and have access to some cells of the sheet but the rest of sheet should stay protected.

Can somebody help me please?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
as the macro is working on the part of sheet which is protected

There ya have it. You'll have to programatically unprotect the sheet at the beginning of the code, and then protect at the end.
 
Upvote 0
There ya have it. You'll have to programatically unprotect the sheet at the beginning of the code, and then protect at the end.
Thanks jproffer. But as I do not know programming, I am not able to write the code in VB editer mode. So I am still stuck.
 
Upvote 0
Open the editor and put this line at the beginning, just before the code that does stuff:

Code:
Thisworkbook.Worksheets ("put the sheet name here").Unprotect ("password")

Then undo this at the end of the code with:

Code:
ThisWorkbook.Worksheets ("put sheet name here").Protect ("yourpassword")
 
Upvote 0
Open the editor and put this line at the beginning, just before the code that does stuff:

Code:
Thisworkbook.Worksheets ("put the sheet name here").Unprotect ("password")

Then undo this at the end of the code with:

Code:
ThisWorkbook.Worksheets ("put sheet name here").Protect ("yourpassword")


Thanks a lot. It works beautifully.
 
Upvote 0
Hi,

I am having the same problem, but when I tried to use this code it kicked out as an invalid outside procedure. I am using Excel 2007. I need to unprotect the worksheet only to run the macro, but the macro itself kicks off every time the user clicks an unlocked cell.

Here is the code I am using to hide rows. I have a hidden column that contains formulas to generate a 0 if there is nothing in the data cells. That way the end users don't have to see things that don't pertain to them.

Any assistance would be fantastic. I am in a bit of a time crunch and I have been banging my head against the wall for the past week just to get this much to work. I am not a programmer.

Thank you.

Joe

P.S. I also tried creating a module for each and got the same result. Finally, do I also need to unprotect the workbook and if so, I will need help with that as well.





Sub HideZeroRows()
Dim w As Worksheet, a As Range, c As Range, s As String
s = "J11:J45" 'The range to check on each sheet
Application.ScreenUpdating = False
For Each w In ThisWorkbook.Worksheets
For Each a In Range(s)
For Each c In a
c.EntireRow.Hidden = (c.Value = 0)
Next c
Next a
Next w
Application.ScreenUpdating = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
HideZeroRows
End Sub
 
Last edited:
Upvote 0
try this after your "Sub HideZeroRows()"

ActiveSheet.Unprotect Password = "yourpassword"

and try this before your "End Sub"

ActiveSheet.Protect Password = "yourpassword"

Hope this works!
 
Upvote 0
Hi there

I put the same code in for the macro, but now the autofilters on the sheet don't work.

Is the macro change related to the filters? I would not have thought so.

Thanks
 
Upvote 0
Open the editor and put this line at the beginning, just before the code that does stuff:

Code:
Thisworkbook.Worksheets ("put the sheet name here").Unprotect ("password")

Then undo this at the end of the code with:

Code:
ThisWorkbook.Worksheets ("put sheet name here").Protect ("yourpassword")

Hello, everyone,
this unlocking and locking of the worksheet is great, but I want to add at the end, ie before the lock allows me to use the following things:
Code:
Sub Dublikati_psix_J()

ThisWorkbook.Worksheets("psix").Unprotect ("my password")

' here is my code

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:= _
        True
    ActiveSheet.EnableSelection = xlNoRestrictions


    ThisWorkbook.Worksheets("psix").Protect ("my password")

End Sub
I tried to put them before, after, but when I pressed the specified button locks and does not allow me to filter as if these criteria were not set.
I ask for some assistance from you.
The worst thing is that I've put this lock and unlock in over 60 buttons and now I see that things are not happening.
Thank you in advance
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
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