Sure, I can help you with that. Here's a VBA code that should do the trick:
Formula:
Sub ClearCells()
Dim lastRow As Long
Dim i As Long
lastRow = Cells(Rows.Count, "H").End(xlUp).Row
For i = 2 To lastRow
If Cells(i, "H").Value = "" Or Cells(i, "H").Value Cells(i, "F").Value Then
Cells(i, "H").ClearContents
Cells(i, "I").ClearContents
Cells(i, "M").ClearContents
Cells(i, "N").ClearContents
End If
Next i
End Sub
Here's how it works:
- The first line declares two variables: lastRow and i. lastRow will be used to determine the last row of data in column H, and i will be used to loop through each row of data.
- The second line uses the function to find the last row of data in column H. It starts at the bottom of the sheet and goes up until it finds the last cell with data.
- The For loop starts at row 2 and goes to the last row of data in column H.
- The If statement checks if the date in column H is blank or greater than the date in column F. If either of these conditions are true, then the cells in columns H, I, M, and N for that row are cleared.
- The Next statement moves the loop to the next row of data.
- Once the loop is finished, all cells in columns H, I, M, and N that meet the specified conditions will be cleared.
I hope this helps! Let me know if you have any questions.