comparing and painting cells

  • Thread starter Thread starter redf1re
  • Start date Start date
R

redf1re

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
 
geez.... my spaces went to hell

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
 
geez.... my spaces went to hell

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
 
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
 
thanks... i made some modifications and it works fine

just another question... i need this macro to run after my user run a
query.... i mean, after i pressed that "!" button to run a query,.,....
what macro name does that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top