Can I run macros on a protected worksheet?

Mel Smith

Well-known Member
Joined
Dec 13, 2005
Messages
1,023
Office Version
  1. 365
Platform
  1. Windows
I have a workbook of 6 worksheets and in them are some 76 macros. I have protected each worksheet's cells that contain formulas. The macros I have set up no longer run now that I have set up the protection. Is there a simple way round this?

Mel
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Turn the protection off at the start of the code, turn it on again at the end of the code
VBA Code:
Sheets("your_sheet_name").UnProtect "your password"
 'rest of your code
Sheets("your_sheet_name").Protect "your password"
There is another method if you are password protecting using code initially
 
Upvote 0
Solution
Hello Mark,

On each sheet there are 15 or so macros. Should I copy your code into each macro?

Mel
 
Upvote 0
Yes, you'll need to do it on every code unless you are using one code to call the others.
 
Upvote 0
OK. Many thanks. Now for a lot of copying and pasting!

Mel
 
Upvote 0
Your welcome (obviously you need to change the sheet name and password to suit)

A bit concerning if you have 15 event macro's in each sheet (assuming that they are event macro's and not regular macro's)
 
Upvote 0
What is wrong with this code? This macro refuses to run?
Sub T20_Bowling_Total_Runs()
Dim rng As Range
Dim cell As Range
Dim maxVal As Double
Sheets("T20 bowling").Unprotect "WWW"

Set rng = Range("CH4:CH23")

maxVal = rng.Cells(1).Value

For Each cell In rng
If cell.Value > maxVal Then
maxVal = cell.Value
End If
Next cell

For Each cell In rng
If cell.Value = maxVal Then
cell.Interior.Color = RGB(255, 255, 0)
End If
Next cell
Sheets("T20 bowling").Protect "WWW"
End Sub


Mel
 
Upvote 0
Mel, is this one of the macro's in the sheet? if yes, is exactly the same macro in the other sheets and is the password the same for the other sheets?
 
Upvote 0

Forum statistics

Threads
1,215,085
Messages
6,123,030
Members
449,092
Latest member
ikke

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