Created
January 6, 2025 12:00
-
-
Save lucabased/c4939f80bc27422465f155ef0c98f3ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub RemoveRowsNotEqualToOneOrBefore2023() | |
| Dim ws As Worksheet | |
| Dim lastRow As Long | |
| Dim i As Long | |
| ' Set the worksheet you want to work with | |
| Set ws = ThisWorkbook.Sheets(1) ' Change 1 to the index or name of your sheet | |
| ' Find the last row in the sheet | |
| lastRow = ws.Cells(ws.Rows.Count, "H").End(xlUp).Row | |
| ' Loop through rows from the bottom to the top | |
| For i = lastRow To 2 Step -1 | |
| ' Check if the value in column H is not 1 or the date in column F is earlier than 2023 | |
| If ws.Cells(i, "H").Value <> 1 Or ws.Cells(i, "F").Value < DateSerial(2023, 1, 1) Then | |
| ws.Rows(i).Delete | |
| End If | |
| Next i | |
| MsgBox "Rows not meeting the criteria have been removed.", vbInformation | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment