Results 1 to 3 of 3

Macro for Highlighting Rows based on Cell Value

Threaded View

  1. #1
    Registered User
    Join Date
    10-28-2008
    Location
    NJ
    Posts
    2

    Macro for Highlighting Rows based on Cell Value

    Hello,

    I am trying to write a macro to highlight a group of cells based on the cell value in column A. The cell values in column A will look like:

    1
    1
    1
    2
    2
    2
    3
    3
    3

    What I need is to highlight all of the rows with a cell value of 1 in one color and highlight all of the rows with the next cell value as another color and finally to highlight all of the rows with the next cell value as the first color.

    I have tried to write a Macro:

    Dim startCell As Range, cell1 As Range, cell2 As Range
    Dim rowNr&
    Set startCell = ActiveCell
    rowNr = startCell.Row: colNr = 45
    
        For rowNr = startCell.Row To 200
            If (Cells(rowNr, 1).Value) = (Cells(rowNr + 1, 1).Value) Then
                Set cell1 = Cells(rowNr, 1)
                
            ElseIf (Cells(rowNr, 1).Value) < (Cells(rowNr + 1, 1).Value) Then
                Set cell2 = Cells(rowNr - 1, 45)
                Range(cell1, cell2).Select
                With Selection.Interior
                .ColorIndex = 15
                .Pattern = xlSolid
                End With
                
            End If
        Next rowNr
        
    End Sub
    But can't seem to get it. Any help would be GREATLY appreciated!

    Best Regards,
    Excel Macro Noob
    Last edited by VBA Noob; 10-28-2008 at 05:02 PM.

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