Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional formatting--different formatting depending on cell con Tammy S. Excel Discussion (Misc queries) 3 March 30th 09 08:11 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 3 January 20th 07 02:02 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 0 January 15th 07 04:35 PM
expanding custom formatting without removing existing cell formatting? Keith Excel Worksheet Functions 3 December 27th 06 01:54 PM


All times are GMT +1. The time now is 08:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"