ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Color Rows (https://www.excelbanter.com/excel-programming/342583-color-rows.html)

smandula

Color Rows
 
Hello,
This VBA hilites 5 rows, I need the last two rows to be a different color,
an color
As of now all rows are a light green

Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Range
Dim i As Long
Dim iPos As Long

Me.Cells.Interior.ColorIndex = xlColorIndexNone
For Each Cell In Target.EntireRow.Cells
For i = 1 To 4
iPos = 0
On Error Resume Next
iPos = Application.Match(Cell.Value, Rows(Target.Row + i),
0)
On Error GoTo 0
If iPos < 0 Then 'return_type' is 1
Cells(Target.Row + i, iPos).Interior.ColorIndex = 35
Cell.Interior.ColorIndex = 35
End If
Next i
If Range("A1").Value = 0 Then Exit Sub
Next Cell

End Sub



Tom Ogilvy

Color Rows
 
If iPos < 0 Then 'return_type' is 1
if i < 3 then
Cells(Target.Row + i, iPos).Interior.ColorIndex = 35
Cell.Interior.ColorIndex = 35
else
Cells(Target.Row + i, iPos).Interior.ColorIndex = 5
Cell.Interior.ColorIndex = 5
End if
End If

--
Regards,
Tom Ogilvy


"smandula" wrote in message
...
Hello,
This VBA hilites 5 rows, I need the last two rows to be a different color,
an color
As of now all rows are a light green

Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Range
Dim i As Long
Dim iPos As Long

Me.Cells.Interior.ColorIndex = xlColorIndexNone
For Each Cell In Target.EntireRow.Cells
For i = 1 To 4
iPos = 0
On Error Resume Next
iPos = Application.Match(Cell.Value, Rows(Target.Row + i),
0)
On Error GoTo 0
If iPos < 0 Then 'return_type' is 1
Cells(Target.Row + i, iPos).Interior.ColorIndex = 35
Cell.Interior.ColorIndex = 35
End If
Next i
If Range("A1").Value = 0 Then Exit Sub
Next Cell

End Sub





smandula

Color Rows
 
Thanks Tom

It works OK!

However, any number on the first row which has the same corresponding number
in the last two rows will take on the Color 5, a darker color. So the first
row
is a mix of Colors 35 & 5. Still provides the same answer.

I can live with that.

With Thanks
Steve





If iPos < 0 Then 'return_type' is 1
if i < 3 then
Cells(Target.Row + i, iPos).Interior.ColorIndex = 35
Cell.Interior.ColorIndex = 35
else
Cells(Target.Row + i, iPos).Interior.ColorIndex = 5
Cell.Interior.ColorIndex = 5
End if
End If

--
Regards,
Tom Ogilvy






All times are GMT +1. The time now is 02:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com