Cell formatting
First watch out for typos.
It's xlNone (with an ELL), not x1None (with a ONE). Second, it looks like you want to look at column A in A4:A41 and color A:S of that row. If that's the case, maybe something like: Option Explicit Sub FormatCells() Dim LastInsp As Range Dim myCell As Range Set LastInsp = Range("a4:a41") For Each myCell In LastInsp.Cells If myCell.Value = 1 Then myCell.Resize(1, 19).Interior.ColorIndex = 3 Else myCell.Resize(1, 19).Interior.ColorIndex = xlNone End If Next myCell End Sub Brian T wrote: I am trying set the cell color for a range of cells by determining the value of a cell in the range. For example if A4=1, I want that row 4 to be red and if a4=0, I want the row to have no color. But my whole range turns red. Here is the code that I have done so far. What am I not getting? Sub FormatCells() 'Create Class 1 Variables 'Class_1 is all information 'LastInsp in the time since the last inspection. Dim Class_1 As Range Dim LastInsp As Range Set Class_1 = Range("a4:s41") Set LastInsp = Range("a4:a41") 'Set color in range. 'Colored background shows that inspection is out of date. Class_1.Interior.ColorIndex = x1None For Each Class_1 In Range("a4:s41") If LastInsp = 1 Then Class_1.Interior.ColorIndex = 3 ElseIf LastInsp = 0 Then Class_1.Interior.ColorIndex = x1None End If Next -- Dave Peterson |
All times are GMT +1. The time now is 06:47 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com