Right now I have the code going from L2 and looping down to the last row in the column. If the cell value is less than the value of a cell from the "Previous" sheet then that cell is highlighted with the ColorIndex of 40. Works great.
What I really want to do though is to be able loop through a second column at the same time (they will both be on the same row at all times obviously). Logically it should go like this:
If the cell value (beginning at L2) is less than the value of a cell from the "Previous" sheet AND if the cell value at AE2 is equal to "#N/A" (note: at this point all formulas have been removed so the "#N/A" is a string) THEN highlight the L2 cell with the ColorIndex of 40. Any help is appreciated.
Sub Comparing()
Sheets("Output").Select
Dim UsedRng As Range, LastRow As Long
Dim x As Long
Set UsedRng = ActiveSheet.UsedRange
LastRow = UsedRng(UsedRng.Cells.Count).Row
Range("L2").Select
Do Until ActiveCell.Row = LastRow + 1
If ActiveCell.Value < Range("Previous!L2") Then
ActiveCell.Interior.ColorIndex = 40
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
EDIT: Thanks for the replies. After tweaking things got the code to work as follows:
Sub Comparing()
Dim wsOut As Worksheet
Dim wsPrev As Worksheet
Dim r As Long
Dim LastRow As Long
Set wsOut = Worksheets("Output")
Set wsPrev = Worksheets("Previous")
LastRow = wsOut.UsedRange(wsOut.UsedRange.Cells.Count).Row
For r = 2 To LastRow
If wsOut.Cells(r, "L").Value < wsPrev.Cells(2, "L").Value And _
Application.WorksheetFunction.IsNA(wsOut.Cells(r, "AE").Value) Then
wsOut.Cells(r, "L").EntireRow.Delete
End If
Next
End Sub