Snake Eyes
Board Regular
- Joined
- Dec 14, 2010
- Messages
- 105
- Office Version
- 365
- 2016
- Platform
- Windows
I have a macro that changes the text and formatting of a cell to indicate if the worksheet is protected or not.
When I run the protection macro it runs fine however, If that button is clicked again I get this error...
I'm trying to piece together code from a somewhat similar macro to bypass the error and stop the macro from running if clicked by mistake after the worksheet has already been protected.
i.e. The cells already contain the text "Protected".
This is what I have so far...
This code doesn't actually stop the macro when the cells contain "Protected".
There's likely something simple I'm missing or maybe even a better way.
Thanks for any assistance.
When I run the protection macro it runs fine however, If that button is clicked again I get this error...
I'm trying to piece together code from a somewhat similar macro to bypass the error and stop the macro from running if clicked by mistake after the worksheet has already been protected.
i.e. The cells already contain the text "Protected".
This is what I have so far...
VBA Code:
Sub Protect_Positions01_10()
'
' Protect_Positions01_10 Macro
'
' Sets Up the Indicator Cell
With Range("I2:K3")
Dim IllegalCharacter(1) As String, i As Integer
IllegalCharacter(1) = "Protected"
For i = 1 To 7
If InStr(.Text, (IllegalCharacter(i))) = "Protected" Then
MsgBox "The worksheet is already protected."
Exit Sub
End If
Range("I2:K3").Select
ActiveCell.FormulaR1C1 = "Protected"
Range("I2:K3").Select
This code doesn't actually stop the macro when the cells contain "Protected".
There's likely something simple I'm missing or maybe even a better way.
Thanks for any assistance.
Last edited: