View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.misc
Josh
 
Posts: n/a
Default Adding colours as a function

I am trying to change the color of a row based on 1 cell with 7 different
inputs giving 7 diff. colors. (Using data validation to prevent any other
input)

I adapted the code posted here (Thank you Otto) And have it working fine,
except;
If I select several lines and change them all at once (Ctrl+Enter) I get an
error message;

Run-time error '13':
Type mismatch

Is there a more stable method?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
If Target.Value = 1 Then
Target.EntireRow.Interior.ColorIndex = 6
End If
If Target.Value = 2 Then
Target.EntireRow.Interior.ColorIndex = 4
End If
If Target.Value = 3 Then
Target.EntireRow.Interior.ColorIndex = 33
End If
If Target.Value = 4 Then
Target.EntireRow.Interior.ColorIndex = 45
End If
If Target.Value = 5 Then
Target.EntireRow.Interior.ColorIndex = 7
End If
If Target.Value = 6 Then
Target.EntireRow.Interior.ColorIndex = 3
End If
If Target.Value = 0 Then
Target.EntireRow.Interior.ColorIndex = xlNone
End If
End If
End Sub

"Otto Moehrbach" wrote:

If you want to change the entire row to red, you will need VBA. Put the
macro below in the sheet module for your sheet. To access that module,
right-click on the sheet tab, select View Code, and paste this macro into
that module. Click on the "X" in the top right corner to get back to your
sheet.
This macro will color the entire row red if the corresponding cell in
Column G goes to zero or less. It will remove the red color if the value
goes above zero. HTH Otto
Private Sub Worksheet_Change(ByVal Target As Range)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 7 Then
If Target.Value <= 0 Then
Target.EntireRow.Interior.ColorIndex = 3
Else
Target.EntireRow.Interior.ColorIndex = xlNone
End If
End If
End Sub

"Billjary" wrote in message
...
hi

Is it possible to highlight a row when a particular cell reaches zero??
For
example if my stock level of oranges in col G reaches zero after orders
are
placed then can i run something that will automatically change that row to
red?

Thanks