View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default comparing and painting cells

Hi,
Try this as a starter:

Sub PaintCells()

Dim lastrow As Long, r As Long, c As Integer

With Worksheets("Sheet1")

lastrow = .Cells(Rows.Count, "E").End(xlUp).Row

For r = 2 To lastrow ' <=== assumes data starts in row 2

Select Case .Cells(r, "A")

Case Is = 1
For c = 5 To 17
If .Cells(r, c) < 0 Then
.Cells(r, c).Interior.ColorIndex = 5
End If
Next c

Case Is = 2
For c = 5 To 17
If .Cells(r, c) < 0 Then
If .Cells(r, c) <= .Cells(r - 1, c) Then
.Cells(r, c).Interior.ColorIndex = 4
Else
.Cells(r, c).Interior.ColorIndex = 3
End If
End If
Next c

End Select

Next r

End With
End Sub

"redf1re" wrote:


hello... if i have the following situation on the seet:


1 0 40,00 20,00 20,00 20,00
2 0 30,00 20,00 20,00 30,00
1 10,00 20,00 40,00 30,00 0
2 20,00 30,00 50,00 0 0


in the "1" row i just want to paint the cell blue and save it to
compare later....
in the 2 row if the value is less than or equal to the value saved in
the same column in the previus row i want it green, if its greater i
want it red

in either rows if i have a "0" value i just want to paint the cell
plain white

the columns are E to Q but the rows range is not defined, but for a 1
row ill always have a 2 row, and it will start with a 1 row.......

can some one help me there plis??

i can program, but not in VBA, if someone just give me a light where i
can find something that can start me up and i take some ideias i can
program myself, that would do too

the algorith would be something like the following

For each cell in the range(E:Q) do
if cell value = 0 then
paint the cell white
else if cell in the first column is 1 then
paint the cell blue
else if cell in the first column is 2
if cell value is less than or equal to the cell in the previus row and
same column
paint the cell green
else if value is greater than the cell in the previus row and same
column
paint the cell red
next cell

thank you


--
redf1re
------------------------------------------------------------------------
redf1re's Profile: http://www.excelforum.com/member.php...o&userid=31258
View this thread: http://www.excelforum.com/showthread...hreadid=511141