Advertisement
sathana

Untitled

Dec 7th, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. Sub ProcessRows()
  2. Dim ws As Worksheet
  3. Dim lastRow As Long
  4. Dim i As Long
  5. Dim earliestDate As Date
  6. Dim latestDate As Date
  7.  
  8. Set ws = ThisWorkbook.Sheets("Data(10-30-23)")
  9.  
  10. ' Find the last row with data in column A
  11. lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
  12.  
  13. ' Loop through each row
  14. For i = 2 To lastRow ' Assuming data starts from row 2
  15.  
  16. ' Find the earliest date among the specified columns
  17. earliestDate = Application.WorksheetFunction.Min( _
  18. ws.Cells(i, "AG"), ws.Cells(i, "AH"), ws.Cells(i, "AI"), _
  19. ws.Cells(i, "AJ"), ws.Cells(i, "AK"), ws.Cells(i, "AL"), _
  20. ws.Cells(i, "AM"), ws.Cells(i, "AN"), ws.Cells(i, "AP"), _
  21. ws.Cells(i, "AS"), ws.Cells(i, "AZ"), ws.Cells(i, "AW"), _
  22. ws.Cells(i, "BB"))
  23.  
  24. ' Find the latest date among the specified columns
  25. latestDate = Application.WorksheetFunction.Max( _
  26. ws.Cells(i, "AG"), ws.Cells(i, "AH"), ws.Cells(i, "AI"), _
  27. ws.Cells(i, "AJ"), ws.Cells(i, "AK"), ws.Cells(i, "AL"), _
  28. ws.Cells(i, "AM"), ws.Cells(i, "AN"), ws.Cells(i, "AP"), _
  29. ws.Cells(i, "AS"), ws.Cells(i, "AZ"), ws.Cells(i, "AW"), _
  30. ws.Cells(i, "BB"))
  31.  
  32. ' Input the earliest and latest dates to columns EL and EM
  33. ws.Cells(i, "EL").Value = earliestDate
  34. ws.Cells(i, "EM").Value = latestDate
  35.  
  36. ' Check if there is a date in column EK and if it is before the date in column EM
  37. If Not IsEmpty(ws.Cells(i, "EK").Value) And ws.Cells(i, "EK").Value < latestDate Then
  38. ' Highlight the entire row in red
  39. ws.Rows(i).Interior.Color = RGB(255, 0, 0)
  40. End If
  41. Next i
  42. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement