Results 1 to 5 of 5

Conditional formatting based on two criteria

Threaded View

  1. #1
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    179

    Conditional formatting based on two criteria

    Hi all,

    I have a macro that runs on another workbook to format it for the user. I would like ONLY the cells in the E column where the cell above in the A column is equal to the current cell in the A column and the DAY value for days wait (E column) is greater than 7 to be highlighted. I basically want it highlight the cells where the days wait is greater than 7.

    Here's what I have so far:

    Sub Sort()
    
    Dim MyFile As String
    Dim Lr As Long 'last row
    Dim rng As Range
    Dim Day As Integer
    
    MyFile = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
    Workbooks.Open (MyFile)
    
    Columns("B:AE").Delete
    Columns("D:D").Delete
    Range("D8").Value = "Date Confirmed"
    Range("D9").FormulaR1C1 = "=DATE(MID(RC[-2],7,4),MID(RC[-2],4,2),MID(RC[-2],1,2))"
    
    
    Range("D9", "D" & Range("C9").End(xlDown).Row).Name = "MyRange"
    Range("D9").AutoFill Destination:=Range("MyRange")
    Range("E8").Value = "Proc order/Time gap"
    Range("E9").FormulaR1C1 = _
        "=IF(RC[-4]=R[-1]C[-4],TEXT(RC[-2]-R[-1]C[-2]+(RC[-1]-R[-1]C[-1]),""dd\:hh:mm:ss""),RC[-4])"
    Range("E9").AutoFill Destination:=Range("E9:E324")
    
    Lr = Range("E" & Rows.Count).End(xlUp).Row
    
    For Each rng In Range("E9", "E" & Lr)
    Day = Val(Left(rng, 2))
    
        If rng <> rng.Offset(0, -1).Value Then
            If rng = "*:*" And Day > 7 Then
                rng.Offset(-1, 0).Resize(2, 1).Interior.ColorIndex = 3 'red
            End If
        End If
    Next rng
    Range("D:E").Columns.AutoFit
    
    End Sub
    But it still doesn't seem to get them to be highlighted.

    Please see the attached file to see example of the unhighlighted version and the what the finished version should look like.

    Example.xlsx

    Thanks for you anticipated help.
    Last edited by Brumbot; 01-24-2013 at 05:45 AM.
    Did I help? Click *- add to my rep.

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