Formatting the background of unlocked cells

R

roniaelm

Hello,

I have this code that enables users to change the font colour of
unlocked cells to red of a protected sheet without needing the
password:

Sub Macro2()
With Selection
ActiveSheet.Unprotect Password:="password"
With Selection.Font
.Color = -16776961
End With
End With
ActiveSheet.Protect Password:="password"
End Sub

How can I use this same code but format the background colour of a
cell to red rather then the font colour?

Thanks for all of your help!
 
J

John Bundy

You want to use .Interior.ColorIndex = 3

put this in and run to see all the colors if you want.

Sub main()
For i = 1 To 50
Cells(i, 1).Interior.ColorIndex = i
Next
End Sub
 
R

roniaelm

You want to use .Interior.ColorIndex = 3

put this in and run to see all the colors if you want.

Sub main()
For i = 1 To 50
Cells(i, 1).Interior.ColorIndex = i
Next
End Sub
--
-John
Please rate when your question is answered to help us and others know what
is helpful.









- Show quoted text -

Hi John,

Thanks so much for your help,

I have integrated this into the code as follows but I recieve an error
when I do.
I am not sure what I am doing wrong?

Sub Macro2()
With Selection
ActiveSheet.Unprotect Password:="overview"
With Selection.Font
.Interior.ColorIndex = 3
End With
End With
ActiveSheet.Protect Password:="overview"
End Sub

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top