Thread: Banding groups
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Banding groups

The following will create bands, alternating between no bands and light-gray
bands, grouped by data (or lack thereof) in column A. As in your example,
the Fords will be gray, GM will be uncolored, Honda will be gray, and so
on. The bands need not have the same number of rows.

Change the lines of code marked with '<<< to suit your specific needs.

Sub AAA()

Dim LastRow As Long
Dim FirstRow As Long
Dim RowNdx As Long
Dim Band As Boolean
Const COLUMNS_TO_BAND = 10 '<<< Change to number of columns wide to shade
Const BAND_COLORINDEX = 15 '<<< 15 = Light gray

Band = False '<<< False to have first band grey, True to have first band
white
FirstRow = 1 '<<< Change to first row number of data to band.
LastRow = Cells(Rows.Count, "B").End(xlUp).Row '<<< change "B" to sub data
column

For RowNdx = 1 To LastRow
If Cells(RowNdx, "A").Value = vbNullString Then
If Band Then
Cells(RowNdx, "A").Resize(1, COLUMNS_TO_BAND) _
.Interior.ColorIndex = BAND_COLORINDEX 'light grey
End If
Else
Band = Not Band
If Band Then
Cells(RowNdx, "A").Resize(1, COLUMNS_TO_BAND) _
.Interior.ColorIndex = BAND_COLORINDEX 'light grey
End If
End If
Next RowNdx

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Habanerotary" wrote in message
...
For readability, I would like to be able to band a spreadsheet that has
been
grouped. Either of the following solutions would work...

Ex:

Ford
Mustang
F-150
General Motors
Corvette
Silverado
Honda
S2000
Ridgeline
Element

1. (Preferred) Alternate grey (G) and white (W) background on rows at
level
1 and have all child rows inherit that background color.

(G) Ford
(G) Mustang
(G) F-150
(W)General Motors
(W) Corvette
(W) Silverado
(G)Honda
(G) S2000
(G) Ridgeline
(G) Element

2. (Acceptable) Set a grey background for all rows at level 1 and a white
background for all child rows.

(G) Ford
(W) Mustang
(W) F-150
(G)General Motors
(W) Corvette
(W) Silverado
(G)Honda
(W) S2000
(W) Ridgeline
(W) Element

Obviously, this involves Conditional Formatting, but how can I ask a row
if
it's group level or how can I band child rows to follow their parent row
when
the parent rows alternate background color?

Thanks!