+ Reply to Thread
Results 1 to 5 of 5

alternating line color with same values

  1. #1
    Registered User
    Join Date
    03-20-2009
    Location
    holon
    MS-Off Ver
    Excel 2003
    Posts
    18

    alternating line color with same values

    I need to write a macro in order to format a worksheet so that the line colors are alternating (ex: red and yelow), for easy reading

    11 mark 11 with red
    11 mark 11 with red
    25 mark 25 with Yellow
    25 mark 25 with Yellow
    25 mark 25 with Yellow
    09 mark 9 with red
    09 mark 9 with red
    44 mark 44 with Yellow
    55 mark 55 with red

    this values are in one column

    thanks

  2. #2
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: alternating line color with same values

    try this macros

    Please Login or Register  to view this content.
    usage - place the cursor on the first cell contain the data ..
    and run macros

  3. #3
    Registered User
    Join Date
    03-20-2009
    Location
    holon
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: alternating line color with same values

    thanks

    but what wrong with this code


    Sub color_it()
    Dim p As Range

    Set p = Workbooks("paint.XLS").Sheets("1").Range("a2:a7")
    xcolor = vbRed
    Do While p.Value <> ""
    x = ActiveCell.Value
    Do While ActiveCell.Value = x
    ActiveCell.Interior.Color = xcolor
    ActiveCell.Offset(1, 0).Activate

    Loop

    If xcolor = vbRed Then
    xcolor = vbGreen
    Else
    xcolor = vbRed
    End If
    Loop
    End Sub

    i get type mismatch for p

  4. #4
    Registered User
    Join Date
    03-20-2009
    Location
    holon
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: alternating line color with same values

    THIS IS THE NEW CODE

    Sub color_it()
    Dim p As Range



    Set p = Workbooks("paint.XLS").Sheets("1").Range("a2:a7")
    p.Activate
    xcolor = vbRed
    Do While ActiveCell.Value <> ""
    x = ActiveCell.Value
    Do While ActiveCell.Value = x
    ActiveCell.Interior.Color = xcolor
    ActiveCell.Offset(1, 0).Activate

    Loop

    If xcolor = vbRed Then
    xcolor = vbGreen
    Else
    xcolor = vbRed
    End If
    Loop
    End Sub

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: alternating line color with same values

    Please read the forum rules, and then edit both your posts to add code tags.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1