+ Reply to Thread
Results 1 to 4 of 4

Highlight entire row based on nonempty cell

Hybrid View

  1. #1
    Registered User
    Join Date
    01-27-2014
    Location
    Fresno, USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Highlight entire row based on nonempty cell

    Greetings,

    I have a formula which is looped down column A and another formula that is looped down column B. I'm trying to figure out how to highlight the entire row yellow if a cell is nonempty in column A and highlight the entire row red if a cell is nonempty in column B. Here is my code:

    Sub Formulas()
    Dim mycell As Range
    With Sheets("Sheet1")
    .Range("A1").EntireColumn.Insert
    .Range("A1").EntireColumn.Insert
    .Cells(1, 1) = "Indicator3 >= 2"
    .Cells(1, 2) = "True Failure"
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    .Range(.Cells(2, 1), .Cells(lr, 1)).FormulaR1C1 = "=IF(AND(RC[4]='F',(AND(ISNUMBER(SEARCH('ECONOMICS',R[1]C[3])),R[1]C[4]='P')),(ISNUMBER(R[1]C[5]))),R[1]C[5]-RC[5],0)"
    .Range(.Cells(2, 2), .Cells(lr, 1)).FormulaR1C1 = "=IF(AND(RC[3]='F',NOT(AND(ISNUMBER(SEARCH('ECONOMICS',R[1]C[2])),R[1]C[3]='P')),(ISNUMBER(RC[4]))),1,0)"
    End With
    
    With Sheets("Sheet1")
    For Each mycell In ActiveWorkbook.Worksheets("Sheet").Range(.Cells(2, 1), .Cells(lr, 1))
        If mycell.Value <> "" Then
        
            mycell.Interior.Color = vbYellow
                
        End If
    Next
    End With
    
    With Sheets("Sheet1")
    For Each mycell In ActiveWorkbook.Worksheets("Sheet").Range(.Cells(2, 2), .Cells(lr, 1))
        If mycell.Value <> "" Then
        
            mycell.Interior.Color = vbRed
                
        End If
    Next
    End With
    End Sub
    Any help is much appreciated.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Highlight entire row based on nonempty cell

    Well, if you want to change the color if the cell is empty, then the <> need to become =. e.g.
    If mycell.Value = "" Then
    To set an entire row, you would do something like this
    mycell.entirerow.interior.color = vbYellow
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Registered User
    Join Date
    01-27-2014
    Location
    Fresno, USA
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Highlight entire row based on nonempty cell

    That did the trick! Thanks!

    Sub Formulas()
    Dim mycell As Range
    With Sheets("Sheet1")
    .Range("A1").EntireColumn.Insert
    .Range("A1").EntireColumn.Insert
    .Cells(1, 1) = "Indicator3 >= 2"
    .Cells(1, 2) = "True Failure"
    lr = Cells(Rows.Count, 3).End(xlUp).Row
    .Range(.Cells(2, 1), .Cells(lr, 1)).FormulaR1C1 = "=IF(AND(RC[4]=""F"",(AND(ISNUMBER(SEARCH(""ECONOMICS"",R[1]C[3])),R[1]C[4]=""P"")),(ISNUMBER(R[1]C[5]))),R[1]C[5]-RC[5],0)"
    .Range(.Cells(2, 2), .Cells(lr, 2)).FormulaR1C1 = "=IF(AND(RC[3]=""F"",NOT(AND(ISNUMBER(SEARCH(""ECONOMICS"",R[1]C[2])),R[1]C[3]=""P"")),(ISNUMBER(RC[4]))),1,0)"
    End With
    
    With Sheets("Sheet1")
    lrr = Cells(Rows.Count, 1).End(xlUp).Row
    For Each mycell In ActiveWorkbook.Worksheets("Sheet1").Range(.Cells(2, 1), .Cells(lrr, 1))
        If mycell.Value >= 2 Then
        
            mycell.EntireRow.Interior.Color = vbYellow
                
        End If
    Next
    End With
    
    With Sheets("Sheet1")
    For Each mycell In ActiveWorkbook.Worksheets("Sheet1").Range(.Cells(2, 2), .Cells(lr, 1))
        If mycell.Value = 1 Then
        
            mycell.EntireRow.Interior.Color = vbRed
                
        End If
    Next
    End With
    End Sub

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Highlight entire row based on nonempty cell

    Maybe:

    Sub surePac()
    With Sheets("Sheet1")
    For Each MyCell In ActiveWorkbook.Worksheets("Sheet").Range(.Cells(2, 1), .Cells(lr, 1))
        If MyCell.Value <> "" Then
        
           Rows(MyCell.Row).Interior.color = vbYellow
            
            If MyCell.offset(, 1) <> "" Then
                
                Rows(MyCell.Row).Interior.color = vbRed
                
            End If
       
        End If
    Next
    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Highlight only one Cell in the entire row based on conditions
    By ascool_asice in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-23-2013, 06:15 AM
  2. Replies: 2
    Last Post: 06-05-2013, 11:03 AM
  3. [SOLVED] Using conditional formatting to highlight an entire row based on one cell
    By eizanendoso in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-31-2012, 09:59 AM
  4. Replies: 5
    Last Post: 04-22-2011, 02:50 PM
  5. Highlight entire row based on cell value
    By clwrs in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 08-14-2009, 06:51 PM

Tags for this Thread

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