PC Review


Reply
Thread Tools Rate Thread

Changing Cell Properties when sheet is protected

 
 
Simmer2
Guest
Posts: n/a
 
      17th Oct 2008
Would like to change a cells backgound color based on the value of the cell
using Vba.
If the value in cell is > 0 then turn it green.
If value in cell is < 0 then turn it red.
Would like to have the sheet protected to guard against user changes to cell
formulas.
Using EXCEL 2003.
Any help much appreciated.

--
Cam
 
Reply With Quote
 
 
 
 
JMB
Guest
Posts: n/a
 
      17th Oct 2008
Conditional formatting is tailor made for this operation, but if you must use
VBA...

Any particular cell(s) or just any cell on the worksheet? Do you want to
color the cells as the data is entered or is the data already entered and you
want to color the cells after the fact?

If you right click on the sheet tab, select view code, and paste this into
the code window, it should shade any cell on the sheet as data is entered
into it (assuming you're using the default color palette):

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo CleanUp
Application.EnableEvents = False

With Target
If IsNumeric(.Value) Then
If .Value < 0 Then
.Interior.ColorIndex = 3
ElseIf .Value > 0 Then
.Interior.ColorIndex = 10
End If
End If
End With

CleanUp:
Application.EnableEvents = True
End Sub


"Simmer2" wrote:

> Would like to change a cells backgound color based on the value of the cell
> using Vba.
> If the value in cell is > 0 then turn it green.
> If value in cell is < 0 then turn it red.
> Would like to have the sheet protected to guard against user changes to cell
> formulas.
> Using EXCEL 2003.
> Any help much appreciated.
>
> --
> Cam

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Cell Colour in Protected Sheet Coope Microsoft Excel Discussion 1 1st Apr 2009 07:55 PM
Changing Font in an unlocked cell in a protected sheet. Mark T UK Microsoft Excel Misc 2 3rd Oct 2008 12:03 PM
Changing font on a protected sheet Kate Microsoft Excel New Users 1 2nd Oct 2004 01:27 AM
Changing a Chart on a Protected Sheet Peter M Microsoft Excel Programming 2 24th Feb 2004 06:48 PM
Keeping properties on unlocked cells constant in a protected sheet PC Microsoft Excel Misc 0 16th Jul 2003 12:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:13 PM.