VBA Error setting Font.ColorIndex

  • Thread starter Thread starter Steve Barnett
  • Start date Start date
S

Steve Barnett

I've got this very simplistic idea that, when a user changes the text in a
cell, I want to change the colour of the text so they can keep track of what
has been changed and what hasn't. This all seemed very simple, and I ended
up with code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Font.ColorIndex = 3
End Sub

Very simple indeed. However, it doesn't work. When I come to set the
ColorIndex, the macro fails with an error 1004, "Unable to set the
ColorIndex property of the Font class"

Having failed at that, I tried changing other properties, such as the Color
and Bold properties. All of these failed with the same error. Irritating
thing is, the help file shows an example of setting the ColorIndex of a Font
object, so it must be possible to do.

Anyone know why this wouldn't work?

Thanks
Steve

Office 2003/Excel 2003, Windows/XP SP2 (pro and home)
 
Yes.

Had another play - and realised that the sheet I was modifying was protected
(It's not my spreadsheet - I'm doing someone a favour - will I never learn!)

I modified the code to unprotect the sheet, change the property and
re-protect it and everything is now working fine.

Thanks
Steve
 
That's odd. I thought of that and tried with a protected sheet, but got
nowhere near that error!
 

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

Similar Threads


Back
Top