Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub ProcessRows()
- Dim ws As Worksheet
- Dim lastRow As Long
- Dim i As Long
- Dim earliestDate As Date
- Dim latestDate As Date
- Set ws = ThisWorkbook.Sheets("Data(10-30-23)")
- ' Find the last row with data in column A
- lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
- ' Loop through each row
- For i = 2 To lastRow ' Assuming data starts from row 2
- ' Find the earliest date among the specified columns
- earliestDate = Application.WorksheetFunction.Min( _
- ws.Cells(i, "AG"), ws.Cells(i, "AH"), ws.Cells(i, "AI"), _
- ws.Cells(i, "AJ"), ws.Cells(i, "AK"), ws.Cells(i, "AL"), _
- ws.Cells(i, "AM"), ws.Cells(i, "AN"), ws.Cells(i, "AP"), _
- ws.Cells(i, "AS"), ws.Cells(i, "AZ"), ws.Cells(i, "AW"), _
- ws.Cells(i, "BB"))
- ' Find the latest date among the specified columns
- latestDate = Application.WorksheetFunction.Max( _
- ws.Cells(i, "AG"), ws.Cells(i, "AH"), ws.Cells(i, "AI"), _
- ws.Cells(i, "AJ"), ws.Cells(i, "AK"), ws.Cells(i, "AL"), _
- ws.Cells(i, "AM"), ws.Cells(i, "AN"), ws.Cells(i, "AP"), _
- ws.Cells(i, "AS"), ws.Cells(i, "AZ"), ws.Cells(i, "AW"), _
- ws.Cells(i, "BB"))
- ' Input the earliest and latest dates to columns EL and EM
- ws.Cells(i, "EL").Value = earliestDate
- ws.Cells(i, "EM").Value = latestDate
- ' Check if there is a date in column EK and if it is before the date in column EM
- If Not IsEmpty(ws.Cells(i, "EK").Value) And ws.Cells(i, "EK").Value < latestDate Then
- ' Highlight the entire row in red
- ws.Rows(i).Interior.Color = RGB(255, 0, 0)
- End If
- Next i
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement