Macro error with sheet protection

Wembley53

New Member
Joined
Feb 19, 2008
Messages
26
Hi,

I have a worksheet that contains a button with an assigned macro to display some text. The macro (below) basically changes the font colour.

Sub ShowQ1()
'
' ShowQ1 Macro
'
Application.Goto Reference:="R5C3"
Selection.Font.ColorIndex = 0
End Sub

This works fine when none of the worksheet is protected. However if I protect the worksheet I get a runtime error 1004. Unable to set the ColorIndex property of teh font class.

The protection is not on the cells that the macro will affect.

Has anyone any ideas how I get around this?

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try like this

Code:
Sub ShowQ1()
'
' ShowQ1 Macro
'
ActiveSheet.Unprotect Password:="zzz"
Application.Goto Reference:="R5C3"
Selection.Font.ColorIndex = 0
ActiveSheet.Protect Password:="zzz"
End Sub
 
Upvote 0
:) This similar thing happened to me today.... But mine was a Macro that changed cell colors, so here is what I figured out by doing a SEARCH here on the topic ;)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    tRow = Target.Row
    tAddress = Target.AddressLocal(False, False)

[COLOR="Red"]ActiveSheet.Unprotect ("your password here")[/COLOR]    
    If Not Intersect(Target, Range("B" & tRow & ",H" & tRow & ",N" & tRow & ",U" & tRow)) Is Nothing Then
        If tAddress = "B" & tRow And Target.Value <> "" Then Range("A" & tRow & ":U" & tRow).Interior.ColorIndex = 3
        If tAddress = "H" & tRow And Target.Value <> "" Then Range("A" & tRow & ":U" & tRow).Interior.ColorIndex = 6
        If tAddress = "N" & tRow And Target.Value <> "" Then Range("A" & tRow & ":U" & tRow).Interior.ColorIndex = 4
        If tAddress = "U" & tRow And Target.Value <> "" Then Range("A" & tRow & ":U" & tRow).Interior.ColorIndex = -4142
[COLOR="red"]ActiveSheet.Protect ("your password here")[/COLOR]    End If
End Sub



hope that turned out right, you see the code in RED is all I added to my existing code, works like a champ. good luck !!!

M :biggrin:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,882
Members
452,948
Latest member
Dupuhini

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