I have an IF statement that partially worked on another spreadsheet but isn't doing what it's supposed on my current one.
What it's supposed to do is find Current End of Month (IE 10/31/2015), -1 Month (so 9/30/2015) + 1 day to give me the Beginning of this month (IE 10/1/2015). Then I want to check the Beginning of this month with Column "H". If the Date in Column "H" is LESS THAN the Beginning of this month (IE 10/1/2015) then blah blah blah.
Here is the entire code in context.
I've provided a book example of what I'm talking about.
https://app.box.com/s/u9crvde2ny5mvco8gq52ktmv4zwlkx3j
Note that simply a <= Month change won't work as there are dates that need to be deleted from the previous year that have higher months.
Code:
If Application.WorksheetFunction.EoMonth(Date, -1) + 1 < Month(sh1.Cells(jRow, "H").Value) Then 'Deletes any Row that is Dates prior to current Month
What it's supposed to do is find Current End of Month (IE 10/31/2015), -1 Month (so 9/30/2015) + 1 day to give me the Beginning of this month (IE 10/1/2015). Then I want to check the Beginning of this month with Column "H". If the Date in Column "H" is LESS THAN the Beginning of this month (IE 10/1/2015) then blah blah blah.
Here is the entire code in context.
Code:
Sub dClosedAsOf()
Dim sh1 As Worksheet 'Current Worksheet
Dim LastRow As Long 'Finds last row
Dim jRow As Long 'Used in row deletion
Set sh1 = Sheets("Closed as of")
'====Delete Rows from Column F===
LastRow = sh1.Range("F1").CurrentRegion.Rows.Count
For jRow = LastRow To 2 Step -1
If Application.WorksheetFunction.EoMonth(Date, -1) + 1 <= Month(sh1.Cells(jRow, "H").Value) Then 'Deletes any Row that is Dates prior to the Beginning of Current Month
Cells(jRow, "F") = "#N/A"
End If
Next jRow
Columns("F").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
'Note for MrExcel readers, this is just one part of a series of row deletion processes which does a mass delete at the end. I've edited out everything but just what's involved in this section of the code.
End Sub
I've provided a book example of what I'm talking about.
https://app.box.com/s/u9crvde2ny5mvco8gq52ktmv4zwlkx3j
Note that simply a <= Month change won't work as there are dates that need to be deleted from the previous year that have higher months.