Consulting

Results 1 to 7 of 7

Thread: Color Rows or Colums

  1. #1

    Color Rows or Colums

    Is there a simple macro program so that when it is executed on sheet, it will color all the cells in every 5th row/column in grey?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To LastRow Step 5

    .Rows(i).Interior.ColorIndex = 15
    Next i
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks for the formula. I can't seem to make it run. Does it matter that I have excel 2003?

  4. #4
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    do you have any data in column a?

  5. #5
    No data, was testing it on a blank sheet. Thanks, it works.

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can also use Mod
    [VBA]For i = 1 To 500
    If i Mod 5 = 1 Then Rows(i).Interior.ColorIndex = 15
    Next[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
        Dim row As Long, col As Long
        For row = 1 To Sheet1.Rows.Count Step 5
         For col = 1 To Sheet1.Columns.Count Step 5
            Sheet1.Cells(row, col).Interior.Color = 12632256
         Next
        Next
    Chris
    ------



Posting Permissions

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