[RESOLVED] Need a vba code to give alternate shading in rows.
Hi all,
I have a data table - names, address, city, phone, etc.
It is 700 lines long.
I want to shade every other row for easy reading across but I don't want to do it cell by cell 350 times.
I'd have to believe there is a way to format it in Word that it can automatically do this but I can't find it.
Need a vba code to do this stuff.
Any help anyone????
Thanx
CS.
Re: Need a vba code to give alternate shading in rows.
Record a macro, and then take a look at the code that it generates. You should get an idea or two on how to create a loop to colorize the whole document.
Re: Need a vba code to give alternate shading in rows.
I have done this in excel..
If u want me to help on this let me know...
Re: Need a vba code to give alternate shading in rows.
If you shade the rows all of the grid lines will go away. Do you want any cell outlines to remain? If so, you will have to format all of the cell with outlines.
Is your data contiguous to the end, or are there gaps or rows formatted differently within the data range?
Here is some code to play with:
Code:
Option Explicit
Sub Macro1()
Dim StartRow As Long
Dim EndRow As Long
Dim StartColumn As Integer
Dim EndColumn As Integer
Dim x As Long
' You should determine the range programmatically, but here is
' some starter code.
StartRow = 1 'Set the Starting Row for coloration
EndRow = 700 'Set the Ending Row for coloration
StartColumn = 1 'Set the Starting Column for coloration
EndColumn = 4 'Set the Ending Column for coloration
'Some Colors:
' -4142 White
' 34 Light Blue
' 36 Light Yellow
' 15 Light Gray
' 6 Yellow
' 1 Black
' 0 Transparent (default)
For x = StartRow To EndRow
If x Mod 2 = 1 Then 'Odd numbered lines
Range(Cells(x, StartColumn), Cells(x, EndColumn)).Interior.ColorIndex = 34
Else 'Even numbered lines
Range(Cells(x, StartColumn), Cells(x, EndColumn)).Interior.ColorIndex = 15
End If
x = x + 1
Next x
End Sub