View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Pikus Pikus is offline
external usenet poster
 
Posts: 5
Default Color every 'nth' row?

Here's the short answer:

nRows = InputBox("Highlight every n rows")

For x = 1 To 100
If x Mod nRows = 1 Then <<Or exchange the number 1
With Rows(x).Interior
.ColorIndex = 6
End With
End If
Next x

You can change a few things to perfect this.

-For x = 1 To 100
Change "100" to whatever you want to be the last possible
highlighted Row Or "nRows * 20" for instance if you want
20 rows colored.
Either way you must give some limit to the number of
hilighted rows or you'll get an error.

-If x Mod nRows = 1 Then
Leaving this line as it is always hilights the first row
and highlights every x rows after that. If you want to
start hilighting with the row whose number you enter (i.e.
when you enter "4" it highlights the 4th row and every 4th
row thereafter) you chould change the number 1 to 0.

-.ColorIndex = 6
The number 6 here means yellow. Here are the meanings of
the numbers 1 - 5:
1 = Black
2 = White
3 = Red
4 = Green
5 = Blue
The numbers 1 through 56 will work here. You can use this
to learn their corresponding colors:

For x = 1 To 56
Rows(x).Interior.ColorIndex = x
Next x

-----Original Message-----

Does anyone know how i can create a macro that will allow

me to color
every 'nth' row? I'm thinking a box would pop up asking

which row to
color, ie if i wanted to color every fourth row i'd enter

4, if iwanted
to color every 17th row i'd enter 17 etc... and on

clicking OK the
backgroud color of the respective rows would change color?

Any ideas?


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step

guide to creating financial statements
.