View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
external usenet poster
 
Posts: 3,885
Default Changing cell color based on its value

Hi
try
Sub ColorCellBasedOnCellValue()
'Colors a cell in column based on its value
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range
For Each cell In Cells(Rows.Count, "B")
Select Case cell.Value
Case 20
cell.Interior.ColorIndex = 7
Case 0
cell.Interior.ColorIndex = 7
End Select
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

But why don't you use 'Format - Conditional Format' for this?


--
Regards
Frank Kabel
Frankfurt, Germany


Hi I'am trying to create a macro which should change the backround
color of a cell based on its value in column B. My code is going
through, but it does't do any coloring, whats wrong, am I somehow
wrong referring to to the column B?


Sub ColorCellBasedOnCellValue()
'Colors a cell in column based on its value
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range
For Each cell In Cells(Rows.Count, "B")
Select Case cell.Value
Case Is = 20
cell.Interior.ColorIndex = 7
Case Is = 0
cell.Interior.ColorIndex = 7


End Select
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
End Sub


---
Message posted from http://www.ExcelForum.com/