Consulting

Results 1 to 6 of 6

Thread: Highlight row based on cell value

  1. #1
    VBAX Regular mike31z's Avatar
    Joined
    Apr 2005
    Location
    Highland, Wisconsin
    Posts
    98
    Location

    Highlight row based on cell value

    Hi, all.
    What I would like to achieve is to highlight (a light pastel color) a row from column A to P if the value of 2 is in column AC for that row.

    I would also highlight (a different light pastel color) a row from column A to P if the value of 4 is in column AC for that row.

    I would also need to turn off the highlighting when done. Conditional formating would not work because the full worksheet is sorted multiple ways.

    I can then copy the code and change AC to AA for a different sort.

    I have attached a sample xls file.

    From the attached XL file you can see that column AC is one sort column, Column AA is another sort column. AC and AA are Vlookup columns all the other columns are actual values.

    I use excel 2000 but have access to excel2007 if needed.
    Attached Files Attached Files

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    For each cell in range("AC2:AC" & Range("A" & Rows.Count).End(xlUp).Row)
        r = cell.row
        if cell.Value = 2 Then
            Range("A" & r & ":P" & r).Interior.ColorIndex = 36
        elseif cell.Value = 4 Then
            Range("A" & r & ":P" & r).Interior.ColorIndex = 43
        End if
    Next cell
    Last edited by Aussiebear; 04-27-2023 at 12:42 PM. Reason: Adjusted the code tags
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    VBAX Regular mike31z's Avatar
    Joined
    Apr 2005
    Location
    Highland, Wisconsin
    Posts
    98
    Location

    Highlight Rows based on cell value

    Thank you that worked on my first test and I can figure out how to undue the highlighting.

    That why I love this forum. Someone is always willing to help if you can explain the problem.

    Mike In Wisconsin

  4. #4
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    hey mike, do you need to hard code the undo? it might be easier to just select all and clear the highlight
    ------------------------------------------------
    Happy Coding my friends

  5. #5
    VBAX Regular mike31z's Avatar
    Joined
    Apr 2005
    Location
    Highland, Wisconsin
    Posts
    98
    Location
    Thanks here is what I used and it works.

    Columns("A:P").Select
        Selection.Interior.ColorIndex = xlNone

    I insert this on top of my other sort macro to clear previous colors and then sort using a different column and the end of the I insert your code modifying the column letters.

    Thanks again
    Last edited by Aussiebear; 04-27-2023 at 12:43 PM. Reason: Adjusted the code tags

  6. #6
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    nice! glad it worked out for you
    ------------------------------------------------
    Happy Coding my friends

Posting Permissions

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