Results 1 to 4 of 4

Thread: [RESOLVED] Need a vba code to give alternate shading in rows.

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Resolved [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.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  3. #3
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    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...

  4. #4
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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
    Last edited by Webtest; Nov 21st, 2005 at 09:19 AM.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width