Consulting

Results 1 to 2 of 2

Thread: Seriously Excel? Change Row Colors

  1. #1

    Seriously Excel? Change Row Colors

    I am beginning to despise Excel more and more with each day.

    I want to take a Worksheet and simply "highlight" every other row yellow.

    My idea was to record a Macro and modify it. Here is the Recorded Macro:

    [vba]Sub Macro1()
    Rows("1:1").Select
    With Selection.Interior
    .ColorIndex = 19
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End With
    End Sub
    [/vba]

    And here is the Modification I made:
    [vba]Sub Macro1()

    For i = 2 to 100 Step 2

    WorkSheets(1).Rows("i:i").Select
    With Selection.Interior
    .ColorIndex = 19
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End With

    Next i
    End Sub
    [/vba]

    Why doesn't that work? It doesn't like the notation ("i:i") for some reason.


  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Try this:
    [vba]
    Sub Macro1()
    Dim i as Long
    For i = 2 To 100 Step 2

    With WorkSheets(1).Rows(i).Interior
    .ColorIndex = 19
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End With

    Next i

    End Sub
    [/vba]
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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