View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Help: format records (color) at each change in continious fiel

Hi,

Here is a macro that should do what you require. If you need instructions
for installing the macro then get back to me.

There are 2 lines of code to initialize the colIdx
('colIdx = 15 'Grey and colIdx = xlColorIndexNone).
Currently the macro is set to have no color in the first row. If you want
the color to start in the first row then remove the single quote from the
first line and place it at the start of the second line.

If you dont like the colors I have used then you can look up colorindex
values. Select Help while in the VBA editor. (this is a different help to
worksheet help so make sure you are in the VBA Editor when you select Help).

In xl2007 enter colorindex as one word in the search and then select
colorindex property.

In earlier versions enter patterncolorindex as one word in the Answer Wizard
search and then select colorindex property.



Sub Alternate_Row_Color()
Dim rngName As Range
Dim colIdx As Integer
Dim i As Long

'Following assumes column header in row 1
'Therefore range assigned to variable starts at row 2
'Edit the sheet name between double quotes to match your sheet name
Set rngName = Sheets("Sheet1").Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp))


'First row color set by following lines
'colIdx = 15 'Grey
colIdx = xlColorIndexNone

With rngName
'Color the first data row grey
.Cells(1, 1).EntireRow.Interior.ColorIndex = colIdx

'Starting at 2nd data row
For i = 2 To .Rows.Count
If .Cells(i) < .Cells(i - 1) Then
If colIdx = 15 Then
colIdx = xlColorIndexNone
Else
colIdx = 15
End If
End If
.Cells(i).EntireRow.Interior.ColorIndex = colIdx
Next i
End With

End Sub



Regards,

OssieMac