Consulting

Results 1 to 5 of 5

Thread: Solved: Highlight ROW based on cell value

  1. #1

    Solved: Highlight ROW based on cell value

    Hi Experts,

    I need help on highlighting entire row ( till only data available up to last column).

    I got a macro from net and i was trying to modify the same. It is not working as i needed. It is highlighting the entire sheet to one particular color.

    But i need to highlight only rows that are having cell value as "Break Down" (Column G) to Some Color. My data range is Column A to Column U only.

    I do not want to color up any row after column U.

    I need to color rows based on the other values on the column G with some other color.

    Can anyone help on this - i have attached a sample work book here

    Thanks in advance
    Raj

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Very small change

    [vba]

    Sub Macro1()
    Const TEST_COLUMN As String = "D" '<=== change to suit
    Dim LastRow As Long
    Dim cell As Range
    sSheetName = ActiveSheet.Name

    With Worksheets(sSheetName)
    LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row

    Range("G2:G" & LastRow).Select

    For Each cell In Selection
    If cell.Value = "Break Down" Then
    cell.EntireRow.Interior.ColorIndex = 39
    ElseIf cell.Value = "PM/SM Call" Then
    cell.EntireRow.Interior.ColorIndex = 43
    Else
    cell.EntireRow.Interior.ColorIndex = xlNone
    End If
    Next
    End With

    End Sub
    [/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
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Better, do it woithout selecting

    [vba]

    Sub Macro1()
    Const TEST_COLUMN As String = "D" '<=== change to suit
    Dim LastRow As Long
    Dim cell As Range
    sSheetName = ActiveSheet.Name

    With Worksheets(sSheetName)
    LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row

    For Each cell In Range("G2:G" & LastRow)
    If cell.Value = "Break Down" Then
    cell.EntireRow.Interior.ColorIndex = 39
    ElseIf cell.Value = "PM/SM Call" Then
    cell.EntireRow.Interior.ColorIndex = 43
    Else
    cell.EntireRow.Interior.ColorIndex = xlNone
    End If
    Next
    End With

    End Sub
    [/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

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    A small change to limit the colouring to Column U
    [VBA]
    Sub Macro1()
    Const TEST_COLUMN As String = "D" '<=== change to suit
    Dim LastRow As Long
    Dim cell As Range
    sSheetName = ActiveSheet.Name

    With Worksheets(sSheetName)
    LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row

    For Each cell In Range("G2:G" & LastRow)
    If cell.Value = "Break Down" Then
    cell.Offset(, -6).Resize(, 21).Interior.ColorIndex = 39
    ElseIf cell.Value = "PM/SM Call" Then
    cell.Offset(, -6).Resize(, 21).Interior.ColorIndex = 43
    Else
    cell.EntireRow.Interior.ColorIndex = xlNone
    End If
    Next
    End With

    End Sub

    [/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'

  5. #5

    Highlight ROW based on cell value

    Hi XLD & MD,

    Thanks to both of you. It is working fine.

    Thank you very much

    Raj

Posting Permissions

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