Hello Everyone, I have a macro code that is supposed to delete the rows on two separate tabs based on the date that is input in a pop up text box, The problem is that the date is a formula and the macro will only delete the rows if I convert the date from a formula to a value. What modifications are needed in the code so it will work if the date is a formula?
VBA Code:
Sub DeleteRows1()
Dim ym As Variant
ym = InputBox("Enter year-month, ex: 2023-5")
If ym = "" Then Exit Sub
If Mid(ym, 5, 1) <> "-" Then
MsgBox "Enter year-month, ex: 2023-5", vbCritical
Exit Sub
End If
If Not IsNumeric(Left(ym, 4)) Then
MsgBox "The year is not correct", vbCritical
Exit Sub
End If
If Not IsNumeric(Split(ym, "-")(1)) Then
MsgBox "The month is not correct", vbCritical
Exit Sub
End If
If Not IsDate("1/" & Split(ym, "-")(1) & "/" & Split(ym, "-")(1)) Then
MsgBox "The date is not correct", vbCritical
Exit Sub
End If
With Sheets("Data1").Range("BC:BC")
.Replace ym, "#N/A", xlWhole
On Error Resume Next
.SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
End With
With Sheets("Data2").Range("AE:AE")
.Replace ym, "#N/A", xlWhole
On Error Resume Next
.SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
End With
'MsgBox "Done"
End Sub